[doctests] Make doctests more robust

Use ellipsis so that Python 2 and Python 3 outputs will pass. Check that
floating point numbers are within 1e-12 of the expected answer rather
than exact matches.