Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 275
microMolvi Avatar asked Nov 01 '25 16:11

microMolvi


1 Answers

Have a look at this article: http://www.edwardrosten.com/code/fp_template.html

(from this article)

First you have to think about how to represent a floating point number in memory:

struct this_is_a_floating_point_number
{
    static const unsigned int mant = ???;
    static const int          expo = ???;
    static const bool         posi = ???;
};

Then 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)

Division might be harder and, for instance, Newtons algorithm could be used to calculate the answer.

Finally, smart approximations and generated values in tables might speed up the calculations at run time.

Many years ago C++ templates helped me getting floating point calculations on an Intel 386 SX

In the end I learned a lot of math and C++ but decided at the same time to buy a co-processor.

Especially 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.

like image 162
Emond Avatar answered Nov 04 '25 14:11

Emond