ProgrammingVery hardJEE Advanced · CAT placement

What is printed?

What is printed?
import math
print(f'{-0.0}', -0.0 == 0.0, math.copysign(1, -0.0))
  1. A. -0.0 True 0.0
  2. B. -0.0 True -1.0
  3. C. -0.0 False -1.0
  4. D. -0.0 True 2.0

Correct answer: B. -0.0 True -1.0

IEEE 754 keeps a signed zero, so -0.0 prints with its sign but still compares equal to 0.0. copysign reads the sign bit directly, which is why it returns -1.0 here.

More Python Programming questions

Exams that ask this topic