How does an Arduino handle the floating point division and other arithmetic without having a floating point unit?

Hello guys,

I am bit curious about how an Arduino handle floating point arithmetic without having a FPU. When I searched for this what I could find out was there are some baseline libraries which maps the work to integer format. But I would like to know how that is done. What is the integer representation of floating points. If anyone can provide me a thorough explanation (using Computer Organization) I would be really thankful.

Just like you would do decimal arithmetic by hand, except in binary. The code is open source, so take a look. You might start here: Math and floating-point support | Microsoft Learn

The FPU uses the same method, but microcoded.

1 Like

It is done in software. If you use floating point in your code the resulting executable will be larger by 1K-2K bytes as it will include the float routines at link time.

1 Like

@yas_g what does that mean?

It's not "integer" :wink: and of course it's binary. Floating Point Binary

Slowly.

It is better to use integers and small units. Example is working millivolts instead of decimal volts.

float doc

If you can, avoid division and get a substantial speed improvement:

  • For example, instead of val = t / 1000;, use val = t * 0.001;
  • reference

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.