cancel
Showing results for 
Search instead for 
Did you mean: 

Question on Floating Point operations

xpp07
Senior

I've heard that floating point operations are very time consuming. However, I've seen that many STM32 include a floating point unit. I'm using a L432KC Nucleo. How does it exactly work? As far as I know, L432KC includes this unit which supports hardware floating point operations. I'm programming using CubeMx and SW4STM32 IDE. When I declare float and double precision variables, am I automatically perfoming this with the FPU?

6 REPLIES 6
T J
Lead

after the correct compile flags are set, the operation is full automatic.

and very fast compared to the software FP.

software FP is not so shabby, this is a 32bit processor...

if you need to use floating point in an interrupt you dont want to be waiting around that long.

so you would have to choose a unit with Hardware FP.

The 'L4 has only a 32-bit FPU, so make sure you use only float not double. The constants involved have to be explicitly typed as float, best by 'f' suffix, eg.

float a, b;

a = b + 3.0f;

JW

32-bit floats are where real math problems go to die...

Be very careful to understand the numbers and ranges involved in a computation, end-to-end. The ARM implementations don't hold intermediate values at higher precision levels.

From a beginner perspective they seem like a very simple way of solving a problem, but can be a trap.

The FPU-S in the Cortex-M4 is good for DSP/scaling like work. Not good for large numbers where precision is critical for small changes (least significant digits).

The FPU-D used in some of the Cortex-M7 parts, provides for 64-bit doubles, which have a lot more usable digits.

All the platforms have a serviceable software implementations.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

For real science/engineering applications people used to seek out FORTRAN compilers supporting Intel's 80-bit floating point format. Even so the Intel/Motorola FPU would hold results in the highest precision level while kept inside the registers.

Microsoft basically standardized at 32-bit and 64-bit floating point representation because it made cross platform porting easier, not because it made the math better.

Other math heavy stuff migrated to Itanium and other platforms natively supporting 128-bit floating point.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
xpp07
Senior

Thank you all. I have to use this formula to calculate the current. I don't need much precision.

0690X000006CGh6QAG.png

Relatively small numbers, would be fine.

Where you'll run into trouble is you've got a number like 2 billion, and want represent/differentiate 2B+1 and 2B-1

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..