Beispiel #1
0
        public static MPZ operator %(MPZ lhs, uint rhs)
        {
            MPZ result = new MPZ();

            gmp_lib.mpz_mod_ui(result.Value, lhs.Value, rhs);
            return(result);
        }
Beispiel #2
0
        public static MPZ operator /(MPZ lhs, mpz_t rhs)
        {
            MPZ result = new MPZ();

            gmp_lib.mpz_tdiv_q(result.Value, lhs.Value, rhs);
            return(result);
        }
Beispiel #3
0
        public static MPZ operator %(mpz_t lhs, MPZ rhs)
        {
            MPZ result = new MPZ();

            gmp_lib.mpz_mod(result.Value, lhs, rhs.Value);
            return(result);
        }
Beispiel #4
0
        public static MPZ operator ~(MPZ value)
        {
            MPZ result = new MPZ();

            gmp_lib.mpz_com(result.Value, value.Value);
            return(result);
        }
Beispiel #5
0
        public static MPZ operator *(uint lhs, MPZ rhs)
        {
            MPZ result = new MPZ();

            gmp_lib.mpz_mul_ui(result.Value, rhs.Value, lhs);
            return(result);
        }
Beispiel #6
0
        public static MPZ operator >>(MPZ lhs, int rhs)
        {
            MPZ result = new MPZ();

            gmp_lib.mpz_tdiv_q_2exp(result.Value, lhs.Value, (mp_bitcnt_t)rhs);
            return(result);
        }
Beispiel #7
0
        public static MPZ operator -(uint lhs, MPZ rhs)
        {
            MPZ result = new MPZ();

            gmp_lib.mpz_ui_sub(result.Value, lhs, rhs.Value);
            return(result);
        }
Beispiel #8
0
        public static MPZ Sqrt(MPZ value)
        {
            MPZ result = new MPZ();

            gmp_lib.mpz_sqrt(result.Value, value.Value);
            return(result);
        }
Beispiel #9
0
        public static MPZ BRandom(MPZ count)
        {
            MPZ result = new MPZ();

            gmp_lib.mpz_urandomb(result.Value, MPZ.RandomState.Value, (mp_bitcnt_t)(ulong)count);
            return(result);
        }
Beispiel #10
0
        public static MPZ Cb(MPZ value)
        {
            MPZ result = new MPZ();

            gmp_lib.mpz_pow_ui(result.Value, value.Value, 3U);
            return(result);
        }
Beispiel #11
0
        public static MPZ Pow(MPZ a, MPZ b)
        {
            MPZ result = new MPZ();

            gmp_lib.mpz_pow_ui(result.Value, a.Value, b);
            return(result);
        }
Beispiel #12
0
        public static MPZ Abs(MPZ value)
        {
            MPZ result = new MPZ();

            gmp_lib.mpz_abs(result.Value, value.Value);
            return(result);
        }
Beispiel #13
0
        public static MPZ operator ^(MPZ lhs, MPZ rhs)
        {
            MPZ result = new MPZ();

            gmp_lib.mpz_xor(result.Value, lhs.Value, rhs.Value);
            return(result);
        }
Beispiel #14
0
        public static MPZ operator +(MPZ value)
        {
            MPZ result = new MPZ();

            gmp_lib.mpz_abs(result.Value, value.Value);
            return(value);
        }
Beispiel #15
0
        public static MPZ Neg2(MPZ value)
        {
            if (value <= 0)
            {
                return(new MPZ(value));
            }

            return(Neg(value));
        }
Beispiel #16
0
        public static MPZ URandom(MPZ max, bool inclusive = false)
        {
            MPZ result = new MPZ();

            if (inclusive)
            {
                mpz_t tmp = new mpz_t();
                gmp_lib.mpz_init(tmp);
                gmp_lib.mpz_add_ui(tmp, max.Value, 1U);
                gmp_lib.mpz_urandomm(result.Value, MPZ.RandomState.Value, tmp);
                gmp_lib.mpz_clear(tmp);
            }
            else
            {
                gmp_lib.mpz_urandomm(result.Value, MPZ.RandomState.Value, max.Value);
            }

            return(result);
        }
Beispiel #17
0
        public static MPZ Max(params MPZ[] values)
        {
            if (values.Length == 0)
            {
                throw new System.ArgumentException();
            }

            MPZ result = values[0];

            for (int i = 1; i < values.Length; i++)
            {
                if (values[i] > result)
                {
                    result = values[i];
                }
            }

            return(new MPZ(result));
        }
Beispiel #18
0
 public static MPZ RightShift(MPZ lhs, MPZ rhs)
 {
     return(lhs >> rhs);
 }
Beispiel #19
0
 public static MPZ LeftShift(MPZ lhs, MPZ rhs)
 {
     return(lhs << rhs);
 }