Floating point I/O in GCC for MSP430

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Greetings.
I am using GCC v3.3 compiler for MSP430.
I can't get uprintf() to work for floating point variables.
Here is example code:

float i, k, m;
i = 20.125f;
k = 20.125F;
m = 2.0125E+1;

uprintf( serial_out, "%F \r\n", i );
uprintf( serial_out, "%F \r\n", k );
uprintf( serial_out, "%2.2E \r\n", m );
uprintf( serial_out, "%g \r\n", m );

Compiler messages:

analog9.c:259: warning: double format, float arg (arg 3)
analog9.c:261: warning: double format, float arg (arg 3)
analog9.c:263: warning: double format, float arg (arg 3)
analog9.c:265: warning: double format, float arg (arg 3)

The people who did the port for the MSP430 say; that floating point is a
work in progress but I don't know if my problem is due to missing
facilities. I can perform floating point arithmetic and view the results
using GDB, but it won't print.
The msp-gcc manual says floating point operations work for type float
but not type double. By declaring the variables as float and using the f
suffix, I think the variables must be type float, but the compiler
messages suggest that they are type double. I am puzzled.
Help and suggestions appreciated.
JC


Re: Floating point I/O in GCC for MSP430
Quoted text here. Click to load it

I am not using GCC, but I suspect that you may need to wait until
doubles are fixed.  Standard C operation with the printf family (I am
not familiar with uprintf), with variable number of parameters, is to
do default promotion of parameter types, which includes converting
float parameters to doubles.  The warnings above appear to be about
those normal promotions.

I suspect you need to wait until the code for the floating point to
decimal converter is fixed, or write your own.

Thad

Re: Floating point I/O in GCC for MSP430

Quoted text here. Click to load it



'Sounds painful, but since my application is restricted - no negative
numbers and limited range - it might be doable. Some pages such as
http://www.duke.edu/~twf/cps104/floating.html#hex2dec may give me enough
explanation to do it.
Thanks.
JC


Re: Floating point I/O in GCC for MSP430

Quoted text here. Click to load it

If the range is narrow enough, you can convert the number to integers
for both the whole and fractional parts:

  #include <stdio.h>
  #include <stdlib.h>

  float f;
  int fi,ff;

  fi = f;
  ff = abs((f-fi)*10000);
  printf ("f=%d.%04d\n", fi, ff);

That would work for values [INT_MIN].9999 to [INT_MAX].9999

Thad

Site Timeline