From: Mark Hubbart Date: 2004-09-16T02:49:47+09:00 Subject: Re: Bignum Troubles On Sep 15, 2004, at 9:52 AM, James Edward Gray II wrote: > On Sep 15, 2004, at 10:39 AM, Robert Klemme wrote: > >> Err, can't you just compare them? If it only *seems* that values >> differ >> then there could be any number of other reasons for the differences >> you >> observe. > > My project is a simulation. I have a "dump" from a correct simulator. > I can compare my dump with theirs. > > Part of the simulation includes random number generation. To solve > this, the spec gives you their random number generation system to use > for the purposes of testing. Dumps do not include random numbers that > were generated. > > My simulation agrees with theirs for 938 turns. At 939, we diverge. > The step we part on is 90% about random number generation and I've > tried to verify everything else to the best of my ability. > > I am "guessing", but I think it's a good guess. > >> Bignum ist just integer numbers. AFAIK there is no such thing as a >> precision for this - all digits are correct. > > Well, when you divide two Integers you can get a decimal, right? My > understanding was that "big math" libraries cut off the division at > some point, to keep from choking on repeating decimal results. Please > correct me, if I misunderstand. > > Here's a look at my math: > > def initialize() > # non-related setup work here > > @random_seeds = [ 12345 ] > end > > # and later > > def test_random(limit) > until @random_seeds.size == 5 > @random_seeds.push @random_seeds[-1] * 22695477 + 1 > end > @random_seeds.shift > > return ((@random_seeds[-1] / 65536) % 16384) % limit > end > > test_random() is written to the provided specification, returning an > integer between 0 and limit. > > The spec include the first 100 answers, which I agree with. In fact, > we agree much farther than that. As I said it takes 939 turns for us > to disagree and the random number generator can be used many times in > a turn. > > I believe we see above that @random_seeds should always contain > Bignums (after the initial few Fixnums, of course). > > What you've made me wonder is, what stages does the last line go > through? Does that first division produce a Float? If so, that's > probably my error right there. That first division should always produce an Integer (either Fixnum or Bignum). Are you expecting to get a decimal or a float somewhere? I don't see anywhere in this code where you will get one... It all looks like integer math to me; they should be precise, but with any decimal part truncated. HTH, Mark > > Thanks for your help. > > James Edward Gray II > >