View Single Post
  #12   Spotlight this post!  
Unread 04-02-2007, 11:27
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: printing FLOAT data type on the terminal window

Floats aren't necessarily bad if used in moderation. They don't take any more data memory than a long does as both float and double are 32 bits long. Floating point operations are emulated in software since there is no on-board FPU hardware. The math library linked in uses a modest amount of additional program memory - but there is a lot of program memory available. It doesn't cost any more program memory to do 1 or 1000 float operations once the library is linked in.

What a programmer needs to be aware of is that the software emulation of the floating point operations can take a lot of time. How much time? I wrote a program to test how many floats/second the library could support and it wasn't much... maybe a few 1000s/second and you'd be saturating the PIC. I'll have to go back and re-run the benchmark to remember exactly.

The float/double data type is 8 bits of signed exponent and 24 bits of data - so a 32 bit integer value actually has 8 bits more precision than a float.

As with anything, understanding its weaknesses as well as its strengths will allow you to make a well informed decision based upon tradeoffs. Personally, I try to avoid both longs and floats but sometimes it just makes more sense to use them vs anything else.