from pulseIn in wiring_pulse.h

`unsigned long maxloops = microsecondsToClockCycles(timeout) / 16;`

from Arduino.h

`#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )`

from compiling with verbose output

`-DF_CPU=16000000L`

so then we get

`unsigned long maxloops = ( ((timeout) * (16000000L / 1000L)) / 1000L )/16`

(Why they didn't use UL is beyond me; perhaps they're providing forward compatibility for CPUs with negative clock rates?)

if timeout is 1,000,000UL (1 million microseconds = 1 second):

`unsigned long maxloops = ( ((1000000UL) * (16000000L / 1000L)) / 1000L )/16`

`unsigned long maxloops = ( ((1000000UL) * (16000L)) / 1000L )/16`

(I'm not an expert; I don't know what the multiplication of an unsigned and a signed brings, but I'm going to assume it's unsigned because that is the more dramatic case even though it makes more sense for it to be signed)

`unsigned long maxloops = ( (16000000000L) / 1000L )/16`

OOPS, 16000000000 is bigger than 4,294,967,295, the maximum size of an unsigned long (it's nearly 4 times bigger). If we truncate, we get 3,115,098,112 (which I BELIEVE is -1,557,549,056 if using signed arithmetic)

`unsigned long maxloops = ( (3115098112UL) / 1000L )/16`

`unsigned long maxloops = 3115098/16`

`unsigned long maxloops = 194693`

194693(loops)*(1/16,000,000)(seconds per clock cycle) *16(clock cycles per loop) = 0.194693 seconds. 195 milliseconds. Then there's the problem that the code assumes that it takes 16 clock cycles per loop for each of the loops, but the final one of the three loops is different (it increments an extra variable, width).

At least, there's my math for you.