avr-gcc-list
[Top][All Lists]

## Re: [avr-gcc-list] Is there anything special about using the float or d

 From: Colin O'Flynn Subject: Re: [avr-gcc-list] Is there anything special about using the float or double data type Date: Tue, 23 Sep 2003 17:55:34 -0700 (PDT)

```Hi,

> Is there anything special about using the float or
> double data types in
> AVR-GCC?

As far as I know for just normal use no, they work
great.

> One thing I would like to print the value of the
> float result without
> using the printf libraries. Are there any ftoa()
> type functions. Maybe I
> should simply cast the result back to int and print
> it that way.

I put a ftoa() function online at www.avrfreaks.net,
which works reasonabley well. Maybe avr-libc has one
built-in now, I haven't checked lately.

But if you know that the values will always be between
say -10 and 10, you could multiply by 100 and use a
itoa() routine as well.

> Speed = distance * scale factor / time
>
> As all these are small values on a model I think I
> need to do this using
> floats.

In your case I wouldn't use floats, just have some
multiplication factor. So everything is multiplied by
100 for example, and the final result is just divided
by whatever to eliminate the factor.

For instance measure time in microseconds, so you can
do everything in integers or longs which are faster
and easier...

Regards,

-Colin

> Hi Guys,
>
> Is there anything special about using the float or
> double data types in
> AVR-GCC?
>
> I have a look through the AVRLIB docs and it only
> mentions the special
> math library. However I assume that the absence of
> anything on floats or
> doubles to mean they just work!
>
> One thing I would like to print the value of the
> float result without
> using the printf libraries. Are there any ftoa()
> type functions. Maybe I
> should simply cast the result back to int and print
> it that way.
>
> I'm wanting to do a tiny bit of floating point math
> to calculate the
> speed of a model railroad locomotive going past a
> couple of IR beam
> sensors at a fixed spacing and time the period
> between beam breaks, to
> get the time and then calculate the scaled speed.
>
> This requires the following:
>
> Speed = distance * scale factor / time
>
> As all these are small values on a model I think I
> need to do this using
> floats.
>
>
> Cheers
>
> Alex Shepherd
>
> Phone  (Home) +64 (7) 854 0819