aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-01-20 02:11:26 +0100
committerMattias Andrée <maandree@operamail.com>2014-01-20 02:11:26 +0100
commit586882ccfb7dd3910b019f1c86abbf824c088637 (patch)
treeb6bc37cb84995021a7a6acd5e8cf013baac919b9
parentadd signum (diff)
downloadalgorithms-and-data-structures-586882ccfb7dd3910b019f1c86abbf824c088637.tar.gz
algorithms-and-data-structures-586882ccfb7dd3910b019f1c86abbf824c088637.tar.bz2
algorithms-and-data-structures-586882ccfb7dd3910b019f1c86abbf824c088637.tar.xz
add opposite sign detection
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/algorithms/bits/Signum.java12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/algorithms/bits/Signum.java b/src/algorithms/bits/Signum.java
index 647076c..515e86d 100644
--- a/src/algorithms/bits/Signum.java
+++ b/src/algorithms/bits/Signum.java
@@ -84,6 +84,18 @@ public class Signum
* 1 ^ ((unsigned £{T})value >> (sizeof(£{T}) * CHAR_BITS - 1))
*/
}
+
+ /**
+ * Detect if two integers have opposite signs
+ *
+ * @param a One of the integers
+ * @param b The other of the integers
+ * @return {@code true} iff either {@code a} or {@code b} is negative and the other is positive
+ */
+ public static boolean haveOpposite(£{T} a, £{T} b)
+ {
+ return (x ^ y) < 0;
+ }
£>done
}