2

I am currently using Python 3.6 in Windows 7.

When I use exponent operator(**) with float that gives a large number, I get an unexpected output.

For example, the output of "10^32" differs whether the exponent is in a form of an integer(32) or a float(32.0).

   >>>print (int(10**(32.0)))
   100000000000000005366162204393472

   >>>print (int(10**(32)))
   100000000000000000000000000000000

Using "**"operator in Python(example)

Is there a reason for the different output?

If so, how can i fix the problem?

1 Answers1

0

This is due to the inherent inaccuracy of floating point representation. See Floating point inaccuracy examples and What Every Computer Scientist Should Know About Floating-Point Arithmetic.

Imran
  • 12,950
  • 8
  • 64
  • 79