trinity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tyson.w.smith@gmail.com
To: davej@codemonkey.org.uk
Cc: trinity@vger.kernel.org, Tyson Smith <tysmith@motorola.com>
Subject: [PATCH 09/12] Actually flip the sign of the value (1 -> -1)
Date: Fri,  6 Mar 2015 14:34:09 -0800	[thread overview]
Message-ID: <1425681249-28725-1-git-send-email-tyson.w.smith@gmail.com> (raw)

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

                 reply	other threads:[~2015-03-06 22:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1425681249-28725-1-git-send-email-tyson.w.smith@gmail.com \
    --to=tyson.w.smith@gmail.com \
    --cc=davej@codemonkey.org.uk \
    --cc=trinity@vger.kernel.org \
    --cc=tysmith@motorola.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).