Home:ALL Converter>Floating point math on a processor that does not support it?

Floating point math on a processor that does not support it?

Ask Time:2013-10-01T12:54:36         Author:microMolvi

Json Formatter

How is floating point math performed on a processor with no floating point unit ? e.g low-end 8 bit microcontrollers.

Author:microMolvi,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/19108279/floating-point-math-on-a-processor-that-does-not-support-it
Emond :

Have a look at this article: http://www.edwardrosten.com/code/fp_template.html\n\n(from this article)\n\nFirst you have to think about how to represent a floating point number in memory:\n\nstruct this_is_a_floating_point_number\n{\n static const unsigned int mant = ???;\n static const int expo = ???;\n static const bool posi = ???;\n};\n\n\nThen you'd have to consider how to do basic calculations with this representation. Some might be easy to implement and be rather fast at runtime (multiply or divide by 2 come to mind)\n\nDivision might be harder and, for instance, Newtons algorithm could be used to calculate the answer.\n\nFinally, smart approximations and generated values in tables might speed up the calculations at run time.\n\nMany years ago C++ templates helped me getting floating point calculations on an Intel 386 SX\n\nIn the end I learned a lot of math and C++ but decided at the same time to buy a co-processor. \n\nEspecially the polynomial algorithms and the smart lookup tables; who needs a cosine or tan function when you have sine function, helped a lot in thinking about using integers for floating point arithmetic. Taylor series were a revelation too.",
2013-10-01T05:11:14
Claudiu :

\n In systems without any floating-point hardware, the CPU emulates it using a series of simpler fixed-point arithmetic operations that run on the integer arithmetic logic unit.\n\n\nTake a look at the wikipedia page: Floating-point_unit#Floating-point_library as you might find more info.\n\nIt is not actually the cpu who emulates the instructions. The floating point operations for low end cpu's are made out of integer arithmetic instructions and the compiler is the one which generates those instructions. Basically the compiler (tool chain) comes with a floating point library containing floating point functions.",
2013-10-01T04:57:12
Patricia Shanahan :

The short answer is \"slowly\". Specialized hardware can do tasks like extracting groups of bits that are not necessarily byte-aligned very fast. Software can do everything that can be done by specialized hardware, but tends to take much longer to do it.",
2013-10-01T09:37:36
yy