Skip to content

Navigation Menu

Sign in
Sign up

SafeArithmetic Draft #2791

franz-hoepfinger-4diac started this conversation in Show and tell
Discussion options

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:

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.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /