Example usage for com.google.common.math IntMath mean

List of usage examples for com.google.common.math IntMath mean

Introduction

In this page you can find the example usage for com.google.common.math IntMath mean.

Prototype

public static int mean(int x, int y) 

Source Link

Document

Returns the arithmetic mean of x and y , rounded towards negative infinity.

Usage

From source file:org.sosy_lab.cpachecker.cpa.invariants.CompoundMathematicalInterval.java

/**
 * Checks if the given interval is contained in this state.
 * @param pInterval the interval to check for.
 *
 * @return <code>true</code> if the given interval is contained in the state, <code>false</code> otherwise.
 */// w w w. j ava2s.  com
public boolean contains(SimpleInterval pInterval) {
    if (isTop()) {
        return true;
    }
    if (isBottom() || pInterval.isTop()) {
        return false;
    }
    if (!pInterval.hasLowerBound() && hasLowerBound()) {
        return false;
    }
    if (!pInterval.hasUpperBound() && hasUpperBound()) {
        return false;
    }
    boolean hasLowerBound = pInterval.hasLowerBound();
    boolean hasUpperBound = pInterval.hasUpperBound();
    BigInteger lb = hasLowerBound ? pInterval.getLowerBound() : null;
    BigInteger ub = hasUpperBound ? pInterval.getUpperBound() : null;
    int leftInclusive = 0;
    int rightExclusive = this.intervals.length;
    while (leftInclusive < rightExclusive) {
        int index = IntMath.mean(leftInclusive, rightExclusive);
        SimpleInterval intervalAtIndex = this.intervals[index];
        boolean lbIndexLeqLb = !intervalAtIndex.hasLowerBound()
                || hasLowerBound && intervalAtIndex.getLowerBound().compareTo(lb) <= 0;
        boolean ubIndexGeqUb = !intervalAtIndex.hasUpperBound()
                || hasUpperBound && intervalAtIndex.getUpperBound().compareTo(ub) >= 0;
        if (lbIndexLeqLb) { // Interval at index starts before interval
            if (ubIndexGeqUb) { // Interval at index ends after interval
                return true;
            }
            leftInclusive = index + 1;
        } else { // Interval at index starts after interval
            rightExclusive = index;
        }
    }
    return false;
}

From source file:org.sosy_lab.cpachecker.cpa.invariants.CompoundBitVectorInterval.java

/**
 * Checks if the given interval is contained in this state.
 * @param pInterval the interval to check for.
 *
 * @return <code>true</code> if the given interval is contained in the state, <code>false</code> otherwise.
 *//*from  w ww .j  ava  2s.  c om*/
public boolean contains(BitVectorInterval pInterval) {
    if (isBottom() || pInterval.isTop()) {
        return false;
    }
    if (!pInterval.hasLowerBound() && hasLowerBound()) {
        return false;
    }
    if (!pInterval.hasUpperBound() && hasUpperBound()) {
        return false;
    }
    boolean hasLowerBound = pInterval.hasLowerBound();
    boolean hasUpperBound = pInterval.hasUpperBound();
    BigInteger lb = hasLowerBound ? pInterval.getLowerBound() : null;
    BigInteger ub = hasUpperBound ? pInterval.getUpperBound() : null;
    int leftInclusive = 0;
    int rightExclusive = this.intervals.length;
    while (leftInclusive < rightExclusive) {
        int index = IntMath.mean(leftInclusive, rightExclusive);
        BitVectorInterval intervalAtIndex = this.intervals[index];
        boolean lbIndexLeqLb = !intervalAtIndex.hasLowerBound()
                || hasLowerBound && intervalAtIndex.getLowerBound().compareTo(lb) <= 0;
        boolean ubIndexGeqUb = !intervalAtIndex.hasUpperBound()
                || hasUpperBound && intervalAtIndex.getUpperBound().compareTo(ub) >= 0;
        if (lbIndexLeqLb) { // Interval at index starts before interval
            if (ubIndexGeqUb) { // Interval at index ends after interval
                return true;
            }
            leftInclusive = index + 1;
        } else { // Interval at index starts after interval
            rightExclusive = index;
        }
    }
    return false;
}

From source file:org.sosy_lab.cpachecker.cpa.invariants.CompoundMathematicalInterval.java

private int intervalIndexOf(BigInteger value) {
    if (isBottom()) {
        return -1;
    }/* w  ww.  j  ava2s . co  m*/
    if (isTop()) {
        return 0;
    }
    int leftInclusive = 0;
    int rightExclusive = this.intervals.length;
    int index = rightExclusive / 2;
    while (leftInclusive < rightExclusive) {
        SimpleInterval intervalAtIndex = this.intervals[index];
        boolean lbIndexLeqValue = !intervalAtIndex.hasLowerBound()
                || intervalAtIndex.getLowerBound().compareTo(value) <= 0;
        boolean ubIndexGeqValue = !intervalAtIndex.hasUpperBound()
                || intervalAtIndex.getUpperBound().compareTo(value) >= 0;
        if (lbIndexLeqValue) { // Interval at index starts before the value
            if (ubIndexGeqValue) { // Interval at index ends after the value
                return index;
            }
            // Interval at index ends before the value
            leftInclusive = index + 1;
        } else { // Interval at index starts after the value
            rightExclusive = index;
        }
        index = IntMath.mean(leftInclusive, rightExclusive);
    }
    return index == 0 ? -1 : -index;
}

From source file:org.sosy_lab.cpachecker.cpa.invariants.CompoundBitVectorInterval.java

private int intervalIndexOf(BigInteger value) {
    if (isBottom()) {
        return -1;
    }// ww  w. j av a 2 s  . com
    if (containsAllPossibleValues()) {
        return 0;
    }
    int leftInclusive = 0;
    int rightExclusive = this.intervals.length;
    int index = rightExclusive / 2;
    while (leftInclusive < rightExclusive) {
        BitVectorInterval intervalAtIndex = this.intervals[index];
        boolean lbIndexLeqValue = !intervalAtIndex.hasLowerBound()
                || intervalAtIndex.getLowerBound().compareTo(value) <= 0;
        boolean ubIndexGeqValue = !intervalAtIndex.hasUpperBound()
                || intervalAtIndex.getUpperBound().compareTo(value) >= 0;
        if (lbIndexLeqValue) { // Interval at index starts before the value
            if (ubIndexGeqValue) { // Interval at index ends after the value
                return index;
            }
            // Interval at index ends before the value
            leftInclusive = index + 1;
        } else { // Interval at index starts after the value
            rightExclusive = index;
        }
        index = IntMath.mean(leftInclusive, rightExclusive);
    }
    return index == 0 ? -1 : -index;
}