Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Constant Expressions, ARM M3

$
0
0

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:

  1. Where can I find the specific use of constant expressions (e.g. 0x1234, 0L, 2LL, ...) in the compiler handbook?
  2. What is the reason for the wrong calculation?
    1. the floating point constant is interpreted as double, why is the cast to float necessary?
    2. why is there a different result with uTest and lTest?

Best regards,
Stefan


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>