-
Notifications
You must be signed in to change notification settings - Fork 74
SafeArithmetic Draft #2791
SafeArithmetic
Traingins will follow.
e.g. can do Addition with Clamp to INT_MAX instead of overflow.
Substraction with Clamp to 0 for UINT etc..
Main Idea:
__builtin_add_overflow is a compiler built-in function in GCC and Clang that safely checks if the addition of two integers causes an overflow
here i made FBs SAFE_ADD/SAFE_MUL etc.. which mirror this Idea to the IEC 61499 Word.
Why is it Relevant:
assume you substract 12 from 10 as UDINT. You result in a high number like 4294967285. While this is computational correct, it may be a mathematical Disaster. as you cannot substract 12 from 10, but the most closest Result you want might be 0 instead of 42949672... right ?
with this FBs the User can decide to use that Behaviour. Overflow-Addition etc.. is still available.
References:
- https://github.com/Meisterschulen-am-Ostbahnhof-Munchen/4diac_training1/blob/develop/SafeArithmetic.md
- Add SafeArithmetic module with native FBs and unit tests Meisterschulen-am-Ostbahnhof-Munchen/4diac-forte#43
- Add Safe Arithmetic Library with Saturating Operations Meisterschulen-am-Ostbahnhof-Munchen/4diac_training1#144
Invitation:
anybody is invited to Test and to Feedback.
Detailed Documentation for each Block will follow.
Note
this is Show and tell category, there is no Discussion needed unless you have Feedback (good/bad) to do this, or you tested and found a Bug.
Nothing to Decide.