c - Initializing floating point variable with large literal -


#include <stdio.h>  int main(void) {     double x = 0.12345678901234567890123456789;     printf("%0.16f\n", x);     return 0; }; 

in code above i'm initializing x literal large represented ieee 754 double. on pc gcc 4.9.2 works well. literal rounded nearest value fits double. i'm wondering happens behind scene (on compiler level) in case? behaviour depend on platform? legal?

when write double x = 0.1;, decimal number have written rounded nearest double. happens when write 0.12345678901234567890123456789 not fundamentally different.

the behavior implementation-defined, compilers use nearest representable double in place of constant. c standard specifies has either double above or 1 below.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -