APPENDIX B

Computer Programs

The programs included here are intended to show to avoid some of the pitfalls in implementing the algorithms of Chapters 2 and 3. They are written in Fortran77 as the only widely available language with an extended precision data type. Let maxint be the largest integer such that all integers with modulus up to and including maxint are represented exactly in double precision variables.

B.1.   FORM a × b mod c

This is surprisingly difficult to do with adequate generality. The program given here is fairly slow, but is useful to check the operation of special-purpose code, for example, when implementing congruential generators.

The problems stem from the limited range of the integer type, which typically only represents integers up to 231 − 1, and sometimes 215 − 1. Double precision variables will represent larger integers exactly, with maxint = 253 and 256 on the Corvus and Vax machines described in Appendix A. There will be no warning of loss of accuracy when using double precision variables, so care is needed to ensure that integer terms never exceed maxint in modulus. If a higher precision type than double precision is available it can be substituted. There is still a problem, for the INT function on double precision variables is often restricted to integer parts Image231 − 1, so this function has to be avoided together with the MOD function.

The function ...

Get Stochastic Simulation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.