cancel
Showing results for 
Search instead for 
Did you mean: 

Behavior of floating point divide by zero

SCAN.1
Associate II

Hi, everyone.

I have found a bug in my code resulting division by zero (float).

We get hard fault if we try to divide an integer number by zero. So how does this process work for float numbers? I have tried this code and result is very strange. MCU hangs. After WDT reset, i see Bus Fault has been triggered.

float a, b, c;
c = 0;
a = b / c;

We are using STM32F746 with STM32CubeIDE. SDMMC(FatFS) , Ethernet, FMC, 4 Timers are enabled. One of these timers generates interrupt on every 250uS.

My questions are:

  • How division-by-zero in float numbers affects the MCU?
  • Is it possible to get a trap for this operation?

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
2 REPLIES 2
Piranha
Chief II

It is very helpful. Thank you.