Skip to main content
SCAN.1
Associate II
Jun 14, 2020 1:38 PM UTC
Solved

Behavior of floating point divide by zero

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.

This topic has been closed for replies.
Piranha
PiranhaBest answer
Principal III
Jun 14, 2020 4:45 PM UTC

2 replies

Piranha
PiranhaBest answer
Principal III
Jun 14, 2020 4:45 PM UTC
SCAN.1
SCAN.1Author
Associate II
Jun 14, 2020 5:33 PM UTC

It is very helpful. Thank you.