I have been searching the forum for over an hour trying to find a solution to what i'm seeing, as well as the rest of the internet, but theres nothing i can find. I initialize a variable as a double, however when i print it, it limits the value to 16 digits, and fills in the rest with zeros. This reflects the e38 of a float, not the e308 of a double.
Code:
#include <stdio.h>
#include <float.h>
int main()
{
double x;
double y;
int lim44;
printf( "Enter the number of cycles: ");
scanf( "%d", &lim44);
x = 1.0;
y = 1.0;
do {
/* "Hello, world!" is printed at least one time
even though the condition is false*/
printf( "%.1Lf\n", x );
x = x+y;
lim44 = lim44-1;
printf( "%.1Lf\n", y);
y = y+x;
lim44 = lim44-1;
} while ( lim44 > 0 );
getchar();
}
The Output for sequences 80 to 100:
Code:
37889062373143904.0
61305790721611584.0
99194853094755488.0
160500643816367070.0
259695496911122560.0
420196140727489660.0
679891637638612220.0
1100087778366101900.0
1779979416004714000.0
2880067194370816000.0
4660046610375530500.0
7540113804746346500.0
12200160415121877000.0
19740274219868226000.0
31940434634990100000.0
51680708854858326000.0
83621143489848426000.0
135301852344706760000.0
218922995834555200000.0
354224848179262000000.0
As seen, it gives up after 16 digits, and with rounding this throws the math off more and more every level. Is there a way to correct this? Or am i missing something stupidly simple?
Any help will be appreciated.