Backport expm integer fix

Fixes #4149