Dear all,
I'm confused about the use of constant expressions. Or is it a compiler bug for the TI ARM v5.04?
Here is the sample code with the corresponding result in the line comment:
static float fTest;
static unsigned short uTest;
static unsigned long lTest;
fTest = 0.04; // 0.04 --> OK
uTest = fTest * 1000.0; // 40 --> OK
lTest = fTest * 1000.0; // 39 --> WRONG
lTest = fTest * (float)1000.0; // 40 --> OK
lTest = (unsigned long)(fTest * 1000.0); // 39 --> WRONG
lTest = (unsigned long)(fTest * (float)1000.0); // 40 --> OK
------------------------------------------------------------------------------
Now my questions:
- Where can I find the specific use of constant expressions (e.g. 0x1234, 0L, 2LL, ...) in the compiler handbook?
- What is the reason for the wrong calculation?
- the floating point constant is interpreted as double, why is the cast to float necessary?
- why is there a different result with uTest and lTest?
Best regards,
Stefan