By Alvin Alexander. Last updated: July 23, 2016
Here's the source code for a Scala function to determine whether signs (positive, negative) of two values are opposite:
/** * The "signs are opposite" helper function. */ def signsAreOpposite(x: Double, y: Double): Boolean = { if (x < 0 && y > 0) return true else if (x > 0 && y < 0) return true else return false }
Bear in mind that part of this solution depends on how you want to handle the situation where one (or both) of the values are zero.