Returns a {@link NumericalValue} representing the intersection of the two parameters

@param a the first {@link NumericalValue}
@param b the second {@link NumericalValue}
@return a {@link NumericalValue} representing the intersection of the two parameters
508337
public static NumericalValue intersect (final NumericalValue a, final NumericalValue b) {
        // early exit
        if (a == null || b == null) return null;
        // get ranges of a and b
        int aMin, aMax, bMin, bMax;
        if (a instanceof SingleNumericalValue) {
            final SingleNumericalValue v = (SingleNumericalValue) a;
            aMin = v.getValue();
            aMax = aMin;
        } else {
            final NumericalValueRange r = (NumericalValueRange) a;
            aMin = r.getMin();
            aMax = r.getMax();
        }
        if (b instanceof SingleNumericalValue) {
            final SingleNumericalValue v = (SingleNumericalValue) b;
            bMin = v.getValue();
            bMax = bMin;
        } else {
            final NumericalValueRange r = (NumericalValueRange) b;
            bMin = r.getMin();
            bMax = r.getMax();
        }
        // intersect ranges
        final int min = Math.max(aMin, bMin);
        final int max = Math.min(aMax, bMax);
        if (min == max)
            return SingleNumericalValue.create(min);
        else
            return NumericalValueRange.create(min, max);
    }
832474
public static BigInteger lcm(BigInteger a, BigInteger b) {
		return lcm(a, b, Calculator.BIG_INTEGER_CALCULATOR);
	}
767940
private static  Number times(Number a, Number b) 
  {
    int aType = getType(a);
    int bType = getType(b);
    
    int compType = (aType >= bType) ? aType : bType;
    switch (compType)  
    {
      case INT :
        return new Integer(a.intValue() * b.intValue());
      case LONG :
        return new Long(a.longValue() * b.longValue());
      case FLOAT :
        return new Float(a.floatValue() * b.floatValue());
      case DOUBLE :
        return new Double(a.doubleValue() * b.doubleValue());
      default :
        throw new IllegalStateException();
    }
  }
1012232
public static double max(final double a, final double b) {
        if (a > b) {
            return a;
        }
        if (a < b) {
            return b;
        }
        /* if either arg is NaN, return NaN */
        if (a != b) {
            return Double.NaN;
        }
        /* min(+0.0,-0.0) == -0.0 */
        /* 0x8000000000000000L == Double.doubleToRawLongBits(-0.0d) */
        long bits = Double.doubleToRawLongBits(a);
        if (bits == 0x8000000000000000L) {
            return b;
        }
        return a;
    }
973110
@Override
  public GallicWeight plus(GallicWeight a, GallicWeight b) {
    if (isZero(a)) return b;
    if (isZero(b)) return a;
    if (mode == RESTRICT_GALLIC) {
      if (SHORTLEX_ORDERING.compare(a, b) != 0) {
        throw new IllegalArgumentException("Trying to plus two different gallic weights, which isn't allowed in " +
          "this context. Did you pass a non-functional FST where a functional one was required? a = " + a +
          "; b = " + b);
      }
      double newWeight = this.weightSemiring.plus(a.getWeight(), b.getWeight());
      return GallicWeight.create(new IntArrayList(a.getLabels()), newWeight);
    } else {
      Preconditions.checkState(mode == MIN_GALLIC);
      return this.weightSemiring.naturalLess(a.getWeight(), b.getWeight()) ? a : b;
    }
  }
168242
@javax.annotation.Nonnull
  public static double[] op(@javax.annotation.Nonnull final double[] a, @javax.annotation.Nonnull final double[] b, @javax.annotation.Nonnull final DoubleBinaryOperator fn) {
    assert a.length == b.length;
    @javax.annotation.Nonnull final double[] c = new double[a.length];
    for (int j = 0; j < a.length; j++) {
      c[j] = fn.applyAsDouble(a[j], b[j]);
    }
    return c;
  }
667666
public static <E> Set<E> intersection(Set<E> first, Set<E> second) {
        if (first == null || second == null) {
            return EMPTY_SET;
        }

        Set<E> intersection = new HashSet<>();

        for (E e : first) {
            if (second.contains(e)) {
                intersection.add(e);
            }
        }
        return intersection;
    }
276066
public static int addExact(int a, int b) {
        long result = (long) a + b;
        checkNoOverflow(result == (int) result);
        return (int) result;
    }
1142255
public static int safeMultiply(int a, int b) {
        long total = (long) a * (long) b;
        if (total < Integer.MIN_VALUE || total > Integer.MAX_VALUE) {
            throw new ArithmeticException("Multiplication overflows an int: " + a + " * " + b);
        }
        return (int) total;
    }
728148
public static FloatBinding min(final ObservableFloatValue a, final ObservableFloatValue b) {
        return createFloatBinding(() -> Math.min(a.get(), b.get()), a, b);
    }
614243
public static double innerProduct(double[] a, double[] b) {
    double result = 0.0;
    int len = Math.min(a.length, b.length);
    for (int i = 0; i < len; i++) {
      result += a[i] * b[i];
    }
    return result;
  }
1166947
public static IntegerBinding min(final ObservableIntegerValue a, final int b) {
        return createIntegerBinding(() -> Math.min(a.get(), b), a);
    }
388561
public static double min(final double a, final double b) {
        if (a > b) {
            return b;
        }
        if (a < b) {
            return a;
        }
        /* if either arg is NaN, return NaN */
        if (a != b) {
            return Double.NaN;
        }
        /* min(+0.0,-0.0) == -0.0 */
        /* 0x8000000000000000L == Double.doubleToRawLongBits(-0.0d) */
        long bits = Double.doubleToRawLongBits(a);
        if (bits == 0x8000000000000000L) {
            return a;
        }
        return b;
    }
1139149
@Override
    public double compute(double a, double b) {
        return (a * b) / (2 - (a + b - a * b));
    }
254362
public static String intersectingConcatenate(String a, String b) {

    // find length of maximum possible match
    int lenOfA = a.length();
    int lenOfB = b.length();
    int minIntersectionLen = min(lenOfB, lenOfA);

    // search down from maximum match size, to get longest possible intersection
    for (int size = minIntersectionLen; size > 0; size--) {
      if (a.regionMatches(lenOfA - size, b, 0, size)) {
        return a + b.substring(size, lenOfB);
      }
    }

    // Didn't find any intersection. Fall back to straight concatenation.
    return a + b;
  }
1112233
public static IsNullValue merge(IsNullValue a, IsNullValue b) {
        if (a == b) {
            return a;
        }
        if (a.equals(b)) {
            return a;
        }
        int aKind = a.kind & 0xff;
        int bKind = b.kind & 0xff;
        int aFlags = a.getFlags();
        int bFlags = b.getFlags();

        int combinedFlags = aFlags & bFlags;

        if (!(a.isNullOnSomePath() || a.isDefinitelyNull()) && b.isException()) {
            combinedFlags |= EXCEPTION;
        } else if (!(b.isNullOnSomePath() || b.isDefinitelyNull()) && a.isException()) {
            combinedFlags |= EXCEPTION;
        }

        // Left hand value should be >=, since it is used
        // as the first dimension of the matrix to index.
        if (aKind < bKind) {
            int tmp = aKind;
            aKind = bKind;
            bKind = tmp;
        }
        assert aKind >= bKind;
        int result = mergeMatrix[aKind][bKind];

        IsNullValue resultValue = (result == NO_KABOOM_NN) ? noKaboomNonNullValue(a.locationOfKaBoom)
                : instanceByFlagsList[combinedFlags >> FLAG_SHIFT][result];

        return resultValue;
    }
429455
public static <A> Set<A> intersection(Set<A> first, Set<A> second) {

        HashSet<A> result = new HashSet<A>(first);
        result.retainAll(second);
        return result;
    }