Fix ticket #4930

Hello,

This patch fixes ticket #4930 by avoiding divisions by zero when simplifying numeric calculations. Thanks to consider pulling.

Simon