trinity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 09/12] Actually flip the sign of the value (1 -> -1)
@ 2015-03-06 22:34 tyson.w.smith
  0 siblings, 0 replies; only message in thread
From: tyson.w.smith @ 2015-03-06 22:34 UTC (permalink / raw)
  To: davej; +Cc: trinity, Tyson Smith

From: Tyson Smith <tysmith@motorola.com>

I believe this is what was intended, previously the high bit was just being set.
Perhaps it was meant to be toggled? If that is the case we can add that too.
---
 random.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/random.c b/random.c
index ec20656..d671035 100644
--- a/random.c
+++ b/random.c
@@ -130,7 +130,7 @@ unsigned int rand32(void)
 
 	/* Sometimes flip sign */
 	if (rand_bool())
-		r |= (1L << 31);
+		r = ~r + 1;
 
 	/* we might get lucky if something is counting ints/longs etc. */
 	if (ONE_IN(4)) {
@@ -206,9 +206,9 @@ u64 rand64(void)
 			r |= (1UL << ((__WORDSIZE - 1) - (rand() % 8)));
 	}
 
-	/* randomly flip sign bit. */
+	/* Sometimes flip sign */
 	if (rand_bool())
-		r |= (1UL << (__WORDSIZE - 1));
+		r = ~r + 1;
 
 	return r;
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-03-06 22:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-06 22:34 [PATCH 09/12] Actually flip the sign of the value (1 -> -1) tyson.w.smith

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).