For portability, skip using strtonum
Handle range errors
Be consistent in range checks