Raise an exception when trying to flatten out-of-range values to integer types.

fixes #2