PleasingFungus's Devblog

Dec 11 '11

Iterating over points to find minima/maxima

min = (int.MAX_VALUE, int.MAX_VALUE)
max = (int.MIN_VALUE, int.MIN_VALUE)
for (point in set)
    if (point.x < min.x)
        min.x = point.x
    else if (point.x > max.x)
        max.x = point.x
   
    //same for y…

Today’s exercise for the class: why is this pseudocode wrong? And why has (an implementation of this) been in my codebase for months?

(The example of a set containing a single point may be educational.)

Tags: starhaven bugs apparently it is amateur hour here