From b4b045a8e7c65783d94812553e31ae0282e80cc4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 21 Dec 2011 15:40:22 -0800 Subject: * arith.c (normalize): Linkage changed to extern. * arith.h (normalize): Declared. * rand.c (random): Bugfix: normalize the bignum before returning it. * txr.1: Doc stubs for PRNG functionality. --- ChangeLog | 10 ++++++++++ arith.c | 2 +- arith.h | 1 + rand.c | 2 +- txr.1 | 8 ++++++++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3407d652..933d37f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2011-12-21 Kaz Kylheku + + * arith.c (normalize): Linkage changed to extern. + + * arith.h (normalize): Declared. + + * rand.c (random): Bugfix: normalize the bignum before returning it. + + * txr.1: Doc stubs for PRNG functionality. + 2011-12-21 Kaz Kylheku * rand.c: Added comment about source of algorithm. diff --git a/arith.c b/arith.c index 14696c24..8429f486 100644 --- a/arith.c +++ b/arith.c @@ -73,7 +73,7 @@ static val bignum_dbl_ipt(double_intptr_t di) return n; } -static val normalize(val bignum) +val normalize(val bignum) { if (mp_cmp_mag(mp(bignum), &NUM_MAX_MP) == MP_GT) { return bignum; diff --git a/arith.h b/arith.h index ba8fd958..1b4026b1 100644 --- a/arith.h +++ b/arith.h @@ -25,4 +25,5 @@ */ val make_bignum(void); +val normalize(val bignum); void arith_init(void); diff --git a/rand.c b/rand.c index 0b811b9f..2e504514 100644 --- a/rand.c +++ b/rand.c @@ -192,7 +192,7 @@ val random(val state, val modulus) err = mp_mod(om, m, om); if (err != MP_OKAY) goto invalid; - return out; + return normalize(out); } else if (fixnump(modulus)) { cnum m = c_num(modulus); if (m <= 0) diff --git a/txr.1 b/txr.1 index e064eed5..a8ea5aba 100644 --- a/txr.1 +++ b/txr.1 @@ -5708,6 +5708,14 @@ yields (1 2 3 4 5). In TXR Lisp, this usage can be simulated using .SS Function interp-fun-p +.SS Variable *random-state* + +.SS Function make-random-state + +.SS Function random-state-p + +.SS Functions random-fixnum and random + .SH APPENDIX A: NOTES ON EXOTIC REGULAR EXPRESSIONS Users familiar with regular expressions may not be familiar with the complement -- cgit v1.2.3