Machine-translated by Google. Questions are authored in English.
Top

Discussion

When a variable of data type double is converted into float, then

  • A.Rounding takes place
  • B.Truncation takes place
  • C.The lower order bits are dropped
  • D.None of these

Answer: A

Correct answer: Rounding takes place

Narrowing a double to a float is a value conversion, not a reinterpretation of bits. If the value cannot be represented exactly in single precision, the result is one of the two nearest representable values, chosen according to the current rounding mode - normally to nearest.

So it is rounding rather than truncation, and describing it as dropping the low-order bits is wrong in both senses: the exponent field differs too, and mantissa bits are rounded rather than discarded. If the magnitude is too large for float, the result is infinity.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.