Fix BoundedRational normalization

Bug: 31035142

Change maybeReduce to a static function, so that we can deal correctly
with results that might already be null.

Fix maybeReduce so that it actually returns the reduced result, not
the original. This was an undetected bug that I think only has
performance implications, and that only under conditions that are
unlikely for the calculator. Nonetheless the original code was
pretty silly.

Add tests for the original bug and other conceivable issues in that
vicinity.

Change-Id: I982dbbaff22f6b05f71a101fee38b25d527ed967
2 files changed