From b2924a90cf8257c314110919316e767d3c556a3f Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Sun, 20 Sep 2026 21:09:38 +0800 Subject: samesign --- bits.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'bits.c') diff --git a/bits.c b/bits.c index 951cc91..7e0ed68 100644 --- a/bits.c +++ b/bits.c @@ -50,7 +50,11 @@ int bitXor(int x, int y) { * 1 if x and y have the same sign , 0 otherwise. */ int samesign(int x, int y) { - return 2; + if (!x) + return !y; + if (!y) + return 0; + return !((x ^ y) >> 31); } /* -- cgit v1.2.3