Processing math: 100%
11.001001000011111101101010100010001000 Arithmazium
Home

Opening lines of code

Summarizing the grand introduction of the previous pages, Prof. William Kahan's Paranoia code tests the behavior of a computer's floating point arithmetic. With the user providing no more than return keystrokes when prompted, Paranoia reports its findings on standard output.

Paranoia's analysis is intended to help programmers porting a numerical code from one computer to another. The artful tests arise from decades of experience on mainframes and minicomputers. Computers designed before 1980 exhibited a wide range of different flavors of floating point. By the time Paranoia appeared in 1982, the effort to develop IEEE Standard 754 for floating point arithmetic was already well underway. Today, the task of porting numerical programs is far less onerous than it was four decades earlier.

In 2020, Paranoia may be more interesting to read than to run, but it will detect some deviations from 754-conforming arithmetic, and it may be useful on custom architectures not intended to support the standard.

To run Paranoia, execute the single file paranoia.py. The classic Basic version, ParaBas, treated its output device as a glass tty, printing results in 24×80 chunks. ParaPy produces output fit for a modern scrolling window.

The first lines of the file indicate you should use some version of Python 3. ParaPy does not dip into Python exotica, but it does rely on some v. 3 features. There are two import statements. The math module gives access to useful mathematical functions like log(x) and floor(x). The division import is an idiom regarding integer division; it's good Python practice, but not essential for Paranoia.

#! /usr/bin/python3
# File paranoia.py drives the Paranoia test. Execute this fie.

from __future__ import division  # use // for integer division

import math

At highest level, paranoia.py is a sequence of four chunks:

  1. Opening comments
  2. Initialization of global variables
  3. Support functions
  4. One-pass sequence of tests

This presentation proceeds in approximate execution order, following the sequence of tests. It refers to the many support functions as they are invoked, rather than in order of appearance.

Home