Java BigInteger Value Check isInRange(BigInteger in, int range, double eps)

Here you can find the source of isInRange(BigInteger in, int range, double eps)

Description

Tests whether a given BigInteger is in the following range: [-2^range, 2^(eps * range)-1] (inclusive).

License

BSD License

Parameter

Parameter Description
in The BigInteger to test
range the bit-range specifier
eps an epsilon that's applied on the positive interval

Return

true if it is in between the given range (inclusive), false otherwise

Declaration

public static final boolean isInRange(BigInteger in, int range, double eps) 

Method Source Code


//package com.java2s;
/*/* w  w  w  .ja  va2s. c  om*/
 * This file is part of an unofficial ISO20008-2.2 sample implementation to
 * evaluate certain schemes for their applicability on Android-based mobile
 * devices. The source is licensed under the modified 3-clause BSD license,
 * see the readme.
 * 
 * The code was published in conjunction with the publication called 
 * "Group Signatures on Mobile Devices: Practical Experiences" by
 * Potzmader, Winter, Hein, Hanser, Teufl and Chen
 */

import java.math.BigInteger;

public class Main {
    /**
     * Tests whether a given {@link BigInteger} is in the following range:
     * [-2^range, 2^(eps * range)-1] (inclusive).
     * 
     * @param in The {@link BigInteger} to test
     * @param range the bit-range specifier
     * @param eps an epsilon that's applied on the positive interval
     * @return true if it is in between the given range (inclusive),
     *         false otherwise
     */
    public static final boolean isInRange(BigInteger in, int range, double eps) {
        if (((in.signum() > 0) && (in.bitLength() > (int) (eps * range))
                && (in.compareTo(BigInteger.valueOf(1).shiftLeft(range)) > 0))
                || ((in.signum() < 0) && (in.bitLength() > range)
                        && (in.compareTo(BigInteger.valueOf(-1).shiftLeft(range)) < 0)))
            return false;

        return true;
    }
}

Related

  1. isElementOfZn(BigInteger element, BigInteger n)
  2. isEven(BigInteger x)
  3. isFermatNumber(BigInteger f)
  4. isGoodGaAndGb(BigInteger g_a, BigInteger p)
  5. isIn20PercentRange(BigInteger first, BigInteger second)
  6. isInt(final BigInteger i)
  7. isIntValue(BigInteger bi)
  8. isLessThan(BigInteger valueA, BigInteger valueB)
  9. isLong(BigInteger number)