Extend BoundedRational and UnifiedReal and fix pow(), exp()

Bug: 64852569

Clean up exp() and pow() implementation so that it always
terminates in reasonable time, if the result has reasonable size.
Do not negate the exponent and take the reciprocal of the
result, since that makes some near-zero results extremely
expensive to compute.

Lean more towards using the exp() and ln() implementation
of pow() when there is a choice. The recursive implementation
can be problematic with huge exponents.

Add accurate conversion function from Double.

Improve accuracy of conversion in the other direction. The old version
was prone to just saying NaN or Infinite for rationals with long
representations.

Do something more reasonable about hashCode() and equals() for
these two types, to make them safer to use.

Some minor cleanups, including some minor performance fixes.

A lot of this was driven by attempts to compare UnifiedReal results
to java.lang.Math generated double results.

Test: Ran unit tests (on host only, so far).
Change-Id: If2e47d99841b3b1fec2349acb31608136a71828e
(cherry picked from commit ff47d599ad952853119dbffbe1e4a8ac06924b4a)
2 files changed