lpcware

Using type double in a program.

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by IntStarFoo on Sat Dec 08 16:15:10 MST 2012
Hi There,  I have a problem using the type double in a program on LPC1769.  I can sort of demonstrate my issue using the code below... Can someone explain the results of this code?  The debugger appears to be showing it correctly but when it prints, it gives me unexpected results.


double doubleA = 0;
double doubleB = 0;
double doubleC = 0;
fprintf(stdout, "Using %%d: doubleA:%d, doubleB:%d, doubleC:%d\n", doubleA, doubleB, doubleC);
fprintf(stdout, "Using %%f: doubleA:%f, doubleB:%f, doubleC:%f\n", doubleA, doubleB, doubleC);
doubleA = 0xFF;
doubleB = 0xFF + 0xFF;
doubleC = 0xFF * 0xFF;
fprintf(stdout, "Using %%d: doubleA:%d, doubleB:%d, doubleC:%d\n", doubleA, doubleB, doubleC);
fprintf(stdout, "Using %%f: doubleA:%f, doubleB:%f, doubleC:%f\n", doubleA, doubleB, doubleC);


Produces These results...

Using %d: doubleA:0, doubleB:0, doubleC:0
Using %f: doubleA:, doubleB:, doubleC:
Using %d: doubleA:0, doubleB:1081073664, doubleC:0
Using %f: doubleA:, doubleB:, doubleC:

Outcomes