-
Notifications
You must be signed in to change notification settings - Fork 6
std::i32::MIN % -1 and related #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “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? Sign in to your account
Comments
Hey Robert, for safety-critical systems, unexpected runtime failures are unacceptable. Enforcing these checks aligns with guidelines like MISRA and ensures deterministic behavior, so the use of checked arithmetic functions should be mandatory. However, I think for a safety-critical guideline to be general, there should be a section about when unchecked operations can be used (in performance-critical real-time systems), along with guarantees (formal and manual verifications). |
This is a good question I don't know the answer to -- anyone know? |
In ARM SDIV manual, the signed division of min::i32 by -1 returns min::i32 instead of producing a hardware exception
|
To my knowledge (and skimming the std docs), the behavior here is the same as any other overflow (irrespective of the platform). This will wrap in release, overflow in debug, that is it adheres to |
Thanks for sharing @Veykril! |
do you want to a rule that says used check remainder or make sure that your inputs are not std::i32::MIN % -1
probably std::i32::MIN / -1 and divide by zero as well divide by zero as well
Lot's of devs don't know about std::i32::MIN % -1, because mathematically it should be zero but faults on Intel processors.
If I ran this on a processor that doesn't fault, would it compile differently?
Compliant solution:
The text was updated successfully, but these errors were encountered: