factorial of negative one (-1)

Ken Watford kwatford+python at gmail.com
Mon Nov 1 12:26:30 CET 2010

On Mon, Nov 1, 2010 at 5:42 AM, Hrvoje Niksic <hniksic at xemacs.org> wrote:
> Printing out further digits (without quotes) is not pointless if you
> want to find out the exact representation of your number in python's
> floating point, for educational purposes or otherwise.  Python has a
> little-known but very instructive method for determining the makeup of a
> float:
>>>> 1.1 .as_integer_ratio()
> (2476979795053773, 2251799813685248)

Handy, but if you need the exact representation, my preference is
float.hex, which seems to be the same as C99's %a format.

>>> math.pi.hex()
>>> float.fromhex(math.pi.hex()) == math.pi

Granted, it's not as easy for humans to interpret, but it's useful for
certain things.

More information about the Python-list mailing list