def mulAndCheck()

in core/src/main/scala/com/spotify/featran/transformers/PolynomialExpansion.scala [276:305]


  def mulAndCheck(a: Long, b: Long): Long =
    if (a > b) {
      // use symmetry to reduce boundary cases
      mulAndCheck(b, a)
    } else {
      if (a < 0) {
        if (b < 0) {
          // check for positive overflow with negative a, negative b
          require(a >= Long.MaxValue / b)
          a * b
        } else if (b > 0) {
          // check for negative overflow with negative a, positive b
          require(a >= Long.MinValue / b)
          a * b
        } else {
          // assert b == 0
          0
        }
      } else if (a > 0) {
        // assert a > 0
        // assert b > 0

        // check for positive overflow with positive a, positive b
        require(a <= Long.MaxValue / b)
        a * b
      } else {
        // assert a == 0
        0
      }
    }