Java BigInteger Value Check isIntValue(BigInteger bi)

Here you can find the source of isIntValue(BigInteger bi)

Description

Checks, whether a BigInteger my be converted to an integer, i.e.

License

Apache License

Parameter

Parameter Description
bi The BigInteger to convert.

Return

If bi is in the correct range return true, otherwise return false.

Declaration

public static boolean isIntValue(BigInteger bi) 

Method Source Code

//package com.java2s;
/***********************************************************
 * $Id$/*from  w w w .j ava2 s. c om*/
 * 
 * PKCS#15 cryptographic provider of the opensc project.
 * http://www.opensc-project.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Created: 01.01.2008
 * 
 ***********************************************************/

import java.math.BigInteger;

public class Main {
    private static BigInteger MIN_INT_BIG_INTEGER = BigInteger.valueOf(Integer.MIN_VALUE);
    private static BigInteger MAX_INT_BIG_INTEGER = BigInteger.valueOf(Integer.MAX_VALUE);

    /**
     * Checks, whether a BigInteger my be converted to an integer,
     * i.e. {@link BigInteger#intValue()} does neither overflow nor underflow.
     * 
     * @param bi The BigInteger to convert.
     * @return  If <code>bi</code> is in the correct range return <code>true</code>,
     *          otherwise return <code>false</code>.
     */
    public static boolean isIntValue(BigInteger bi) {
        if (bi.compareTo(MIN_INT_BIG_INTEGER) < 0)
            return false;
        if (bi.compareTo(MAX_INT_BIG_INTEGER) > 0)
            return false;

        return true;
    }
}

Related

  1. isFermatNumber(BigInteger f)
  2. isGoodGaAndGb(BigInteger g_a, BigInteger p)
  3. isIn20PercentRange(BigInteger first, BigInteger second)
  4. isInRange(BigInteger in, int range, double eps)
  5. isInt(final BigInteger i)
  6. isLessThan(BigInteger valueA, BigInteger valueB)
  7. isLong(BigInteger number)
  8. isMersenneNumber(BigInteger n)
  9. isNegative(BigInteger i)