Is there a floating point (FP) package available for the 8052?
Submitted By: Craig Steiner FAQ Last Modified: 09/11/07
- Virtually all 8052 'C' compilers include integrated FP packages in their run-time libraries. If you are writing in assembly language, however, you will find that professional floating point packages are quite expensive. Also keep in mind that FP is slow compared to fixed point or completely integer-based calculations. Before spending time or money on a FP-package, analyze your problem carefully and see if there is any way to get around the need for floating-point.
How to use floating point in C?
Submitted By: Jan Waclawek FAQ Last Modified: 09/11/07
- Although floating point is supported by standard libraries in most of C compilers, it has its specifics in the 8051 world.
First, please note, that the floating point libraries might be not present in limited, evaluation ("eval", "free") versions of commercial C-compilers, due to the significant amount of know-how needed to write these libraries (this is for example case with the evaluation version of the leading 8051 C-compiler, Keil). You might need to purchase a full licence of these compilers to be able to use floating point arithmetics.
Second, please read carefully the manuals coming with the compiler. The floating point arithmetics might impose a couple of requirements (e.g. on storage space), and the format of numbers (precision, range) might not be satisfactory for your application.
On the other hand, the usage of floating point arithmetics in 8051 C-compilers is the same as in any other C-compiler.
And how to use floating point in asm?
Submitted By: Jan Waclawek FAQ Last Modified: 09/11/07
- The easiest way is to use some floating point library. Easily available are the BASIC-52 sources (although it uses a peculiar BCD format of the numbers), or the SDCC libraries.
For those who would like to develop their own libraries, either floating or fixed point, of goniometric and logarithm/exponential functions, one of the ways to go is to use the CORDIC type of algorithms. There is at least one 8051-family on the market (higher end versions of the Infineon XC8xx family) implementing support for these algorithms in hardware.
why avoid floating point
Submitted By: Erik Malund FAQ Last Modified: 09/11/07
- The '51 was never intended as a 'mathematical machine' but rather a process controller. That fact and the fact it is an 8 bit device makes floting point slow and memory usage ntensive.
Many, many applications where the novice 'automatically' goes for a floating point package can be handled much more efficiently and faster by fixed point.
A variant of floting point that, as far as I know, does not have a name is what I would call "fixed math with inserted point" which fit the '51 as a glove.
Now what the heck is that you may ask. I will illustrate with an example (a Cash register).
$1,23 + $0.17, to a novice, seems like a natural app for the standard slow and tedious 'standard' floting point operation, but what is wrong with just doing 123 cents + 17 cents and inserting the decimal point on the display (and in the data stream to the printer), the user will never know the differennce.
The same method can be applied all over (instead of degrees use tenths of degrees, instead of kg use g, instead of ....
Add Information to this FAQ: If you have additional information or alternative solutions to this question, you may add to this FAQ by clicking here.