-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Divide by Zero does not fail when numerator is Zero #7495
New issue
Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? No Sign in to your account
Comments
Interesting observation! Unfortunately, you didn't tell us what version you're running. Is this 2.7.3 or git head? Something in GCC 10's intrinsics may have changed if it only fails under git master... |
I am using Arduino IDE 1.8.12 to build the code. |
Tools->Board->Boards Manager, then filter with "esp" and you should be able to find the number there. |
With the git master on my own system, it hangs and crashes on the first division, as expected. Please post your sketch output as well. And I think you mean "Div 0 does not fail when denominator is zero"... |
2.6.3 |
Upgrade to 2.7.3, the latest release, and with that verison please post the output of the sketch, too, so we can see what you're seeing. |
Output from 2.7.3. Result1 shouldn't be zero but should throw an exception also |
Can you try 1 change to see if it's a GCC core or intrinsics? Change
to
I'm thinking that because the code is so obvious in the sample that the GCC optimizer is constant folding. Making things volatile will better simulate a division op that's not constant since |
With the volatile change, we are now getting an exception of the first divide as expected. |
Thanks for the update. This is a GCC code optimizer issue then. GCC10 (the git master) doesn't have it, so my best guess is that it's something fixed between 4.8 and 10.1. There's nothing we can do in the core about it (master works and it's GCC related), so this looks like there's nothing we can do here. #7496 will make the core actually dump a synthetic div-by-zero error in this case going forward. |
Thanks for investigating. |
Dividing by zero should always throw an exception. If the numerator is also zero it returns zero instead.
Sample Sketch to reproduce:
#include "Arduino.h"
//NodeMCU 0.9 ESP-12 Module
long a;
long b;
long result;
void setup()
{
Serial.begin(115200);
delay (5000);
a = 0;
b = 0;
result = a/b;
Serial.print("Result1 = ");
Serial.println(result);
a = 1;
Serial.print("Result2 = ");
delay(5000);
result = a/b;
Serial.println(result);
}
void loop()
{
}
The text was updated successfully, but these errors were encountered: