Fix division by zero bug in XMP

Fixes #1978