简体   繁体   中英

Implicit conversion of integers to floats in c

I'm having trouble understading why this code's output is 2147483648:

#include <stdio.h>
int main (void){
    float f = 2147483638;
    printf("%f",f);
}

I tried to find explanation using IEEE 754 standard for float representation but using my calculations I get that output should be 2147483520, not 2147483648. Thanks for help!

That is the way that float works on your system.

Note that the C standard is intentionally flexible as to the type and sizes of the floating point types. A float does not have to be an IEEE754 32 bit floating point type.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM