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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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




--- Alex Shepherd <address@hidden> wrote:
> 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.
> 
> Comments?
> 
> Cheers
> 
> Alex Shepherd
> 
> Phone  (Home) +64 (7) 854 0819
> Email: address@hidden 
> 
> 
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list



reply via email to

[Prev in Thread] Current Thread [Next in Thread]