Basis Lab

What a Computer Does to a Number

One Rounding Is Half a Gap, and a Tenth Plus Two Tenths Is Exactly a Tie

Last timeThe Gaps Between Representable Values

The error of a single floating point operation is at most half the gap at its result, one part in two to the 53, and a tenth plus two tenths lands exactly on a midpoint.

What one operation is allowed to do

The rule for a single arithmetic operation is short enough to quote. Take the

two stored values exactly as they are, compute the exact mathematical result,

and return the representable value nearest to it. Addition, subtraction,

multiplication, division and square root are all defined this way, and a

machine that returns anything else is not conforming.

So there is no sloppiness in one operation and no drift that depends on which

machine ran it. But the exact result usually is not representable, so what

comes back is the nearest value that is, and that difference is the error.

That difference has a size, and the size is already fixed by the layout. Write

gg for the distance between neighbouring representable values, which for a

64 bit value in the interval from 2e2^{e} up to 2e+12^{e+1} is g=2e−52g = 2^{e-52},

since the significand holds 52 stored bits after an implied leading one. An

exact result landing anywhere in that interval is at most g/2g/2 from the nearer

of the two values bracketing it, because a point further than half the spacing

from both would have to lie outside the interval they bound.

FIG 1The error of a rounding, as the value being rounded moves
-0.06-0.030.000.030.060.00.51.01.52.0the value being rounded
rounded to one decimal place, a step of 0.1
Rounding to one decimal place is the same mechanism with a step of 0.1 instead of a power of two, and it is drawn here because a step of two to the minus 52 cannot be drawn. The error is a sawtooth running from minus 0.05 to plus 0.05 and resetting at every midpoint. Half the step is not an average or a typical case: it is the edge the sawtooth reaches and never crosses, and it is reached at every midpoint between two representable values.

The error is bounded not because somebody was careful but because there is

nowhere further than half a step to be, and it is a deterministic function of

the input rather than a random disturbance, which is the fact that decides how

a long calculation behaves.

Half a gap, as one number that works everywhere

A bound of g/2g/2 is awkward to carry around because gg depends on where you

are. Divide it by the magnitude and the dependence vanishes. For xx in the

interval from 2e2^{e} to 2e+12^{e+1} the gap is 2e−522^{e-52}, half of it is

2e−532^{e-53}, and the magnitude is at least 2e2^{e}, so the relative error is at

most 2e−53/2e=2−532^{e-53}/2^{e} = 2^{-53}. The exponent cancels. One constant, called the

unit roundoff, therefore covers every magnitude the format reaches.

The lesson stops here

9 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01Why Eight Bits Hold 256 Values and Minus 128 Has No Positive Twin
  2. 02What Really Happens When a Sum Does Not Fitopening only
  3. 03Reading a Real Number Out of Its Bits, and Writing One Tenth Back Inopening only
  4. 04The Gap to the Next Representable Number, and How to Compute Itopening only
  5. 05One Rounding Is Half a Gap, and a Tenth Plus Two Tenths Is Exactly a Tieyou are here
  6. 06Error in a Long Sum Grows Like Root n, Not Like nopening only
  7. 07The Subtraction That Loses Every Correct Digit at Onceopening only
  8. 08Two Zeros, Two Infinities, and a Value Not Equal to Itselfopening only

Read alongside