コード例 #1
0
 /**
  * Returns the smallest integer x > {@code this} which is probably prime as
  * a {@code BigInteger} instance. The probability that the returned {@code
  * BigInteger} is prime is beyond (1-1/2^80).
  *
  * @return smallest integer > {@code this} which is robably prime.
  * @throws ArithmeticException
  *             if {@code this < 0}.
  */
 public static BigInteger NextProbablePrime(BigInteger value)
 {
     if (value.Sign < 0)
     {
         // math.1A=start < 0: {0}
         throw new ArithmeticException(String.Format(Messages.math1A, value));                 //$NON-NLS-1$
     }
     return(Primality.NextProbablePrime(value));
 }
コード例 #2
0
ファイル: BigInteger.cs プロジェクト: bugbit/algebra
        /**
         * Returns the smallest integer x > {@code this} which is probably prime as
         * a {@code BigInteger} instance. The probability that the returned {@code
         * BigInteger} is prime is beyond (1-1/2^80).
         *
         * @return smallest integer > {@code this} which is robably prime.
         * @throws ArithmeticException
         *             if {@code this < 0}.
         */
        public static BigInteger NextProbablePrime(BigInteger value, CancellationToken argCancelToken)
        {
            argCancelToken.ThrowIfCancellationRequested();

            if (value.Sign < 0)
            {
                // math.1A=start < 0: {0}
                throw new ArithmeticException(String.Format(Messages.math1A, value)); //$NON-NLS-1$
            }
            return(Primality.NextProbablePrime(value, argCancelToken));
        }
コード例 #3
0
ファイル: BigInteger.cs プロジェクト: bugbit/algebra
        /// <summary>
        /// Constructs a random <see cref="BigInteger"/> instance in the
        /// range [0, 2^(bitLength)-1] which is probably prime.
        /// </summary>
        /// <param name="bitLength">The length of the new big integer in bits.</param>
        /// <param name="certainty">The tolerated primality uncertainty.</param>
        /// <param name="random">An optional random generator to be used.</param>
        /// <param name="argCancelToken"></param>
        /// <remarks>
        /// The probability that the returned <see cref="BigInteger"/> is prime
        /// is beyond(1-1/2^certainty).
        /// </remarks>
        /// <exception cref="ArithmeticException">
        /// If the given <paramref name="bitLength"/> is smaller than 2.
        /// </exception>
        public BigInteger(int bitLength, int certainty, Random random, CancellationToken argCancelToken)
        {
            if (bitLength < 2)
            {
                // math.1C=bitLength < 2
                throw new ArithmeticException(Messages.math1C); //$NON-NLS-1$
            }
            BigInteger me = Primality.ConsBigInteger(bitLength, certainty, random, argCancelToken);

            sign         = me.sign;
            numberLength = me.numberLength;
            digits       = me.digits;
        }
コード例 #4
0
ファイル: BigInteger.cs プロジェクト: bugbit/algebra
 /**
  * Tests whether this {@code BigInteger} is probably prime. If {@code true}
  * is returned, then this is prime with a probability beyond
  * (1-1/2^certainty). If {@code false} is returned, then this is definitely
  * composite. If the argument {@code certainty} <= 0, then this method
  * returns true.
  *
  * @param certainty
  *            tolerated primality uncertainty.
  * @return {@code true}, if {@code this} is probably prime, {@code false}
  *         otherwise.
  */
 public static bool IsProbablePrime(BigInteger value, int certainty, CancellationToken argCancelToken)
 {
     return(Primality.IsProbablePrime(BigMath.Abs(value), certainty, argCancelToken));
 }
コード例 #5
0
 /**
  * Tests whether this {@code BigInteger} is probably prime. If {@code true}
  * is returned, then this is prime with a probability beyond
  * (1-1/2^certainty). If {@code false} is returned, then this is definitely
  * composite. If the argument {@code certainty} <= 0, then this method
  * returns true.
  *
  * @param certainty
  *            tolerated primality uncertainty.
  * @return {@code true}, if {@code this} is probably prime, {@code false}
  *         otherwise.
  */
 public static bool IsProbablePrime(BigInteger value, int certainty)
 {
     return(Primality.IsProbablePrime(BigMath.Abs(value), certainty));
 }