# Float in linux

**URL:** <https://community.sparkfun.com/t/float-in-linux/3668>\
**Category:** MicroMod\
**Tags:** msp\
**Created:** [February 6, 2007, 9:00pm UTC](https://community.sparkfun.com/t/float-in-linux/3668 "2007-02-06T21:00:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samot83](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@samot83](https://community.sparkfun.com/u/samot83)\
**Post date:** [February 6, 2007, 9:00pm UTC](https://community.sparkfun.com/t/float-in-linux/3668/1 "2007-02-06T21:00:47Z")

</div>

Im working with mspgcc in fedora core 4

i have allmost all working, im compiling, loading, interruptions, but i have now a little problem

my code dont recognize float

so … if you know how can i do something it wold be great …

thanks

---

<div class="post-metadata">

**Author:** ![wiml](https://avatars.discourse-cdn.com/v4/letter/w/48db29/32.png) [@wiml](https://community.sparkfun.com/u/wiml)\
**Post date:** [February 7, 2007, 3:01am UTC](https://community.sparkfun.com/t/float-in-linux/3668/2 "2007-02-07T03:01:58Z")

</div>

> i have allmost all working, im compiling, loading, interruptions, but i have now a little problem
> 
> my code dont recognize float

What do you mean by that? What error or problem are you getting?

---

<div class="post-metadata">

**Author:** ![samot83](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@samot83](https://community.sparkfun.com/u/samot83)\
**Post date:** [February 7, 2007, 4:13pm UTC](https://community.sparkfun.com/t/float-in-linux/3668/3 "2007-02-07T16:13:08Z")

</div>

```auto
[i]#include <msp430x16x.h>
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <signal.h>
#include <io.h>
#include <iomacros.h>
#include "display.h"
#include "adc.h"
#include "keypad.h"
#include "rxir.h"

#define MAX_TH(x) ((190.0 * (float) x) / 200.0)
#define MIN_TH(x) ((177.0 * (float) x) / 200.0)
#define RANGE(x) (MAX_TH(x) - MIN_TH(x))

int min, max, avg;

int line = 0;
int sec = 0;

int pbir_code;

void Init_Osc_X2(void)
{
    // Al enceder la MSP,
    // y a XT1 en modo LF para ACLK

    BCSCTL1 &= ~XT2OFF; // XT2 encendido (8MHz)
    do // wait in loop until crystal is stable
      IFG1 &= ~OFIFG;
    while (IFG1 & OFIFG);
    IE1 &= ~WDTIE; // disable WDT int.
    IFG1 &= ~WDTIFG; // clear WDT int. flag

    BCSCTL2 = SELM_2 | DIVM_0 | SELS | DIVS_0 ; // MCLK <- XT2 | MCLK = 1:1 | SMCLK <- XT2 | SMCLK = 1:1 ;

    WDTCTL = WDTPW | WDTTMSEL | WDTCNTCL | WDTIS1 ; // use WDT as timer, flag each 512 pulses from SMCLK
    while (!(IFG1 & WDTIFG)); // count 1024 pulses from XT2
                                                    // (until XT2's amplitude is OK)
    IFG1 &= ~OFIFG; // clear osc. fault int. flag
}

int key;

void main(void)
{
  Init_Osc_X2();
  _EINT();
  WDTCTL = WDTPW + WDTHOLD;

  init_display();

  CCTL0 = CCIE; // CCR0 habilita interrupci
  CCR0 = 32768 / 1; // 3 Hz ??

  TACTL = TASSEL_1 + MC_1; // reloj ACLK, modo up to CCR0

  TBCCTL0 = CCIE; // CCR0 habilita interrupci
  TBCCR0 = 32768 / 50; // 50 Hz

  TBCTL = TASSEL_1 + MC_1; // reloj ACLK, modo up to CCR0
  TBCCTL1 = OUTMOD_3;

  P4DIR |= BIT1;
  P4SEL |= BIT1;

  init_rxir();

  ADC_INIT_SEQ();

  //_BIS_SR(LPM0_bits + GIE); // modo bajo consumo

  while (1)
    key=getchar();
}

#define CONV(x) ((float) ((x) * REF) / (float) 0xfff)
#define REF 3.3

// Timer A0 rutina de servicio de interrupci
#pragma vector = TIMERA0_VECTOR
interrupt (TIMERA0_VECTOR) Timer_A(void)
{
  int pos = get_pos();
  CONV_ADC_SEQ(0, &min, &max, &avg);
  //printf("m: %3.2f M: %3.2f\np: %3.2f (%3d)", CONV(min), CONV(max), CONV(avg), key);
  printf("hola (%f)\nchao (%d)",3.14,100);
   set_pos(pos);

  TBCCR1 = MIN_TH(TBCCR0) + ((RANGE(TBCCR0) * (float) avg / (float) 0xfff));
}

#pragma vector = TIMERB0_VECTOR
interrupt (TIMERB0_VECTOR) Timer_B(void)
{

}

[/i]

```

Thats my main, and the float did not work

i dont know why … but this code is only de main … and the sistem works perfect, but the float no, for that reason the system thows bad results, but is working

do i explain myself??

---

<div class="post-metadata">

**Author:** ![samot83](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@samot83](https://community.sparkfun.com/u/samot83)\
**Post date:** [February 7, 2007, 9:27pm UTC](https://community.sparkfun.com/t/float-in-linux/3668/4 "2007-02-07T21:27:21Z")

</div>

The problem is the

_printf(%f,3.14)_

that line did not work

and i have the stdio.h included but i dont know, maybe i need another library

if someone knows someyhing … please help me

thanks[/i]

---

<div class="post-metadata">

**Author:** ![wiml](https://avatars.discourse-cdn.com/v4/letter/w/48db29/32.png) [@wiml](https://community.sparkfun.com/u/wiml)\
**Post date:** [February 8, 2007, 8:25am UTC](https://community.sparkfun.com/t/float-in-linux/3668/5 "2007-02-08T08:25:13Z")

</div>

Oh, I see. The %f support in printf takes a lot of code space and it’s common for it to be left out of microcontroller libraries. Sometimes there’s an optional library you can link that has a more complete printf(), but I don’t think there is one for mspgcc.

Probably ‘float’ works everywhere except for printf.

If you need %f support in printf you could try [[replacing your printf with something like this](http://blog.gmane.org/gmane.comp.hardware.texas-instruments.msp430.gcc.user/month=20030701). Or you could just multiply the number by (say) 100 and convert to an integer before printing, if you don’t need the whole dynamic range of a floating-point number.]([http://blog.gmane.org/gmane.comp.hardware.texas-instruments.msp430.gcc.user/month=20030701](http://blog.gmane.org/gmane.comp.hardware.texas-instruments.msp430.gcc.user/month=20030701))
