Related to #2579. This was harder to fix: the underlying longint routines don't handle signed values.