chicken-users
[Top][All Lists]

## [Chicken-users] Value returned from modulo

 From: Jeronimo Pellegrini Subject: [Chicken-users] Value returned from modulo Date: Sat, 28 Aug 2010 08:19:12 -0300 User-agent: Mutt/1.5.20 (2009-06-14)

```Hello,

I was writing a simple PRNG for didatic purposes and found
that in Chicken, modulo may or may not return an exact
integer -- whic is OK, I can just do inexact->exact.
But it seems also that the value varies among systems:

#;1> (define a 1103515245)
#;2> (define b 12345)
#;3> (define m (expt 2 32))
#;4> (define x 631629065)
#;5> (modulo (+ (* a x) b) m)
23163648.0
#;6> (+ (* a x) b)
697012302412608270

Octave also gives me 23163648:
octave:2> mod((1103515245*631629065 + 12345),(2^32))
ans =  23163648

>From Gambit, and SBCL I get 23163662.

Gambit v4.6.0
> (define a 1103515245)
> (define b 12345)
> (define m (expt 2 32))
> (define x 631629065)
> (modulo (+ (* a x) b) m)
23163662
> (+ (* a x) b)
697012302412608270

(Same for Chibi, Gauche and Bigloo)

SBCL:

* (setq a 1103515245)
* (setq b 12345)
* (setq m (expt 2 32))
* (setq x 631629065)
* (mod  (+ (* a x) b) m)

23163662
* (+ (* a x) b)

697012302412608270

Maxima also answers 23163662 and 697012302412608270.

What puzzles me is that the large value (before taking the modulo)
is 697012302412608270 in all systems, but Chiken and Octave will
still return 23163648 from modulo, so it's not that the larger value
was not represented exactly. Why then is 23163648 returned?

I'm not using the numbers egg (I'd like students to do as much as
possible from scratch, using standard Scheme)

I'm using Chicken from git, master branch, compiled oon a 64-bit
machine, so I suppose I can represent all these numbers without
problems:

CHICKEN
(c)2008-2010 The Chicken Team
(c)2000-2007 Felix L. Winkelmann
Version 4.6.0rc1
linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
compiled 2010-08-09 on newton (Linux)

J.

```