ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
x = 2**53
print(float(x + 1) == x, x + 1.0 == x, (x + 2.0) - x, int(float(x + 3)) - x)
  1. A. True True 2.0 2
  2. B. True True 2.0 4
  3. C. True False 2.0 4
  4. D. True True 0.0 4

Correct answer: B. True True 2.0 4

Above 2**53 the gap between doubles is 2, so 2**53 + 3 is exactly halfway between two doubles and rounds to the even one, 2**53 + 4. Ints stay exact, but float(x + 3) does not.

More Python Programming questions

Exams that ask this topic