I just got caught by implementing this...
int x = constrain(obj.popStack(), 500, 1000); Serial.println(x);
Which for me prints "0", and not some number between 500 and 1000!! Oh, the popStack() method returns an integer value off the object's "stack",
int x = obj.popStack(); x = constrain(x, 500, 1000);
Correctly returns the top of the stack, in the range 500 - 1000
The only way I have to explain this behavior is that the constrain function is implemented as a #define MACRO, which when implemented expands to make repeated calls to the popStack() method. Since each call returns a new value from the stack, this would cause this bizarre behavior.
If constrain is a function in the documentation, it should behave as a function- i.e. evaluate the value (once) of an expression in the call parameters, and then call the function. If it (and max() & min()?) are macros, then this should be made clear in the documentation, with appropriate caveats.