Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is 10 to the power not equal to scientific notation for large numbers in Python?

Tags:

python

Why is 10**5 equal to 1e5 but 10**50 is not equal to 1e50 in Python?

Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 10**5 == 1e5
True
>>> 10**50 == 1e50
False

It's true up to 10**22. Then it's false:

>>> 10**22 == 1e22
True
>>> 10**23 == 1e23
False
like image 299
Tomasz Sikora Avatar asked Jul 31 '21 19:07

Tomasz Sikora


People also ask

How do you convert large numbers to scientific notation in Python?

Integer can be converted to scientific notation with the help of {:e} flag with the help of the format method of string. {:e} converts a number both integer or float to scientific notations.

Is powers of ten notation the same as scientific notation?

Scientific notation, also called power-of-10 notation, is a method of writing extremely large and small numbers.

How do you write to the power of 10 in Python?

To raise a number to a power in Python, use the Python exponent ** operator. Python exponent is also related to another similar topic. The Python exponent notation is a way to express big or small numbers with loads of zeros. You can use the exponent notation e or E to replace the powers of ten.


Video Answer


1 Answers

Python 3 supports big integers and uses them whenever it can. 10**50 is a calculation on integers and produces the exact number ten to the fiftieth power. On the other hand, scientific notation always uses floating point, so 1e50 is a floating-point value that's approximately equal to ten to the fiftieth power.

>>> type(10 ** 50)
<class 'int'>
>>> type(1e50)
<class 'float'>
like image 199
Silvio Mayolo Avatar answered Sep 25 '22 07:09

Silvio Mayolo