double can represent every value a float can represent.
Does converting float to double simply extend the mantissa by adding 0 and extend the exponent part by filling sign bits?
I tested some data at http://www.binaryconvert.com/index.html . It works in this way. But I did not find any official definition of the conversion. Does the conversion have any corner case not working this way?
This has very little to do with C; its only guarantee is that converting from float
to double
must preserve the value.
So you're really asking about (presumably) IEEE-754 . There are at least a few ways in which your description doesn't hold:
The exponents for single-precision and double-precision have different biases. So conversion requires more than just sign extension.
Denormal numbers require special handling (they become normal numbers).
NaNs may also require special handling - distinguishing between signalling and quiet NaNs is dependent on the value of the mantissa.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.