Fix the builtin min() and max() functions (and add tests).

Fixes #539