From 586882ccfb7dd3910b019f1c86abbf824c088637 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 20 Jan 2014 02:11:26 +0100 Subject: add opposite sign detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/algorithms/bits/Signum.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') 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 } -- cgit v1.2.3-70-g09d2