Failed to initialize a local double (MSP430)
I've got a MSP430F149 project that requires I use double-precision math (calculating an Excel-compatible date/time). The only problem, I can't get the math to work with doubles. My project disables "treat doubles as floats".
After lots of time and frustration, I discovered the issues seems to be related to initializing local double variables with floating-point values. I found a work-around to keep my project going (use globals), but that seems a little lame. Am I doing something wrong or is CW 2.0.8 (Mac) broken? Here's some sample code that illustrates:
#include <__cross_studio_io.h>
float g2BitsF = 0.25;
double g2BitsD = 0.25;
float g6BitsF = 0.75;
double g6BitsD = 0.75;
void main(void)
{
float l2BitsF = 0.25;
double l2BitsD = 0.25;
float l6BitsF = 0.75;
double l6BitsD = 0.75;
float sumF;
double sumD;
sumF = g2BitsF + g6BitsF;
debug_printf("Global Floats: %.1f\n", sumF);
sumF = l2BitsF + l6BitsF;
debug_printf("Local Floats: %.1f\n", sumF);
sumD = g2BitsD + g6BitsD;
debug_printf("Global Doubles: %.1f\n", sumD);
sumD = l2BitsD + l6BitsD;
debug_printf("Local Doubles: %.1f\n", sumD);
debug_exit(0);
}
The results shown in the debug terminal is:
Global Floats: 1.0
Local Floats: 1.0
Global Doubles: 1.0
Local Doubles: -2.0
Please sign in to leave a comment.
Comments
1 comment