 True of False | Sololearn: Learn to code for FREE!

+3

# True of False

Why is this False: a = 3**45 == int(float(3**45)) print(a) When this is True: a = 3**3 == int(float(3**3)) print(a) I don't understand this logic.

+3

It is linked to something called limited floating point accuracy or precision: https://en.m.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems Basically, floats in their decimal state have to be represented by binary system (deep, deep down in the "computer core" :) This causes problems for all numbers which cannot be precisely represented using powers of 2 - so basically most real numbers. float(3) is represented by a number closest to its representation (it might be something like 3.000000000000000004) which for "small" computations makes no difference, but for large operations likes exponentiation, the inaccuracy might result in a bit different, unexpectedly different, number. Please note that for numbers which are exactly the power of 2, this does not happen. 4.0**100 == 4**100

+1

Try printing this print(int(float(3**34))) print(3**34)

+1

It only started changing at 3**34. Higher level (or lower level) SoloLearners who always gets this question right in the challenge section, come and explain it o!!!

0

Abhay I still do not understand. Have you tried this: print(int(float(3**33))) print(3**33) Does it mean for larger exponentials, it changes or something?