guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] GNU Guile branch, master, updated. release_1-9-11-227-g9


From: Andy Wingo
Subject: [Guile-commits] GNU Guile branch, master, updated. release_1-9-11-227-g9defb64
Date: Tue, 27 Jul 2010 09:37:11 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".

http://git.savannah.gnu.org/cgit/guile.git/commit/?id=9defb64118774c8f1a1f6af05d6f1705e7a40619

The branch, master has been updated
       via  9defb64118774c8f1a1f6af05d6f1705e7a40619 (commit)
      from  17fc9efecbc9cb0c7e32664dbd0e2c863194cd7f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 9defb64118774c8f1a1f6af05d6f1705e7a40619
Author: Andy Wingo <address@hidden>
Date:   Tue Jul 27 11:32:31 2010 +0200

    64-bit random fixes
    
    * libguile/random.c (scm_random): Fix generation of inum randoms with
      more than 32 bits.
    
    * libguile/random.h (scm_t_rstate): Fix a comment.

-----------------------------------------------------------------------

Summary of changes:
 libguile/random.c |   23 ++++++++++++++++++++---
 libguile/random.h |    2 +-
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/libguile/random.c b/libguile/random.c
index 6703dac..83870f6 100644
--- a/libguile/random.c
+++ b/libguile/random.c
@@ -371,9 +371,26 @@ SCM_DEFINE (scm_random, "random", 1, 1, 0,
   SCM_VALIDATE_RSTATE (2, state);
   if (SCM_I_INUMP (n))
     {
-      scm_t_uint32 m = SCM_I_INUM (n);
-      SCM_ASSERT_RANGE (1, n, m > 0);
-      return scm_from_uint32 (scm_c_random (SCM_RSTATE (state), m));
+      unsigned long m = (unsigned long) SCM_I_INUM (n);
+      SCM_ASSERT_RANGE (1, n, SCM_I_INUM (n) > 0);
+#if SCM_SIZEOF_UNSIGNED_LONG <= 4
+      return scm_from_uint32 (scm_c_random (SCM_RSTATE (state),
+                                            (scm_t_uint32) m));
+#elif SCM_SIZEOF_UNSIGNED_LONG <= 8
+      if (m <= SCM_T_UINT32_MAX)
+        return scm_from_uint32 (scm_c_random (SCM_RSTATE (state),
+                                              (scm_t_uint32) m));
+      else
+        {
+          scm_t_uint64 upper, lower;
+          
+          upper = scm_c_random (SCM_RSTATE (state), (scm_t_uint32) (m >> 32));
+          lower = scm_c_random (SCM_RSTATE (state), SCM_T_UINT32_MAX);
+          return scm_from_uint64 ((upper << 32) | lower);
+        }
+#else
+#error "Cannot deal with this platform's unsigned long size"
+#endif
     }
   SCM_VALIDATE_NIM (1, n);
   if (SCM_REALP (n))
diff --git a/libguile/random.h b/libguile/random.h
index 51b9a0c..512b7d2 100644
--- a/libguile/random.h
+++ b/libguile/random.h
@@ -40,7 +40,7 @@
 
 typedef struct scm_t_rstate {
   struct scm_t_rng *rng;
-  double normal_next; /* For scm_c_uniform01 */
+  double normal_next; /* For scm_c_normal01 */
   /* Custom fields follow here */
 } scm_t_rstate;
 


hooks/post-receive
-- 
GNU Guile



reply via email to

[Prev in Thread] Current Thread [Next in Thread]