SafeArithmetic Draft #2791
franz-hoepfinger-4diac
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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_overflowis a compiler built-in function in GCC and Clang that safely checks if the addition of two integers causes an overflowhere i made FBs
SAFE_ADD/SAFE_MULetc.. 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:
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.
All reactions