Fixed a few cases in the Math functions where floating point imprecision...

... caused integral math to yield incorrect results. Fixes #2893.