diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2021-03-29 10:09:05 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2021-03-29 10:09:05 +0300 |
commit | f021dfc21ac0a96270afbdcf9498b14e95619e6f (patch) | |
tree | 890de086ce55d3ef6ba1fbf9adf50ae8696e2ee7 /support/intprops.h | |
parent | 1fc3d1cbc5c31ecd7b232e8845530ce6a6760986 (diff) | |
parent | 559ea397d1737042898ff2f3c7c988704baaae8a (diff) | |
download | egawk-f021dfc21ac0a96270afbdcf9498b14e95619e6f.tar.gz egawk-f021dfc21ac0a96270afbdcf9498b14e95619e6f.tar.bz2 egawk-f021dfc21ac0a96270afbdcf9498b14e95619e6f.zip |
Merge branch 'master' into feature/bool
Diffstat (limited to 'support/intprops.h')
-rw-r--r-- | support/intprops.h | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/support/intprops.h b/support/intprops.h index 967e32ea..9d10028a 100644 --- a/support/intprops.h +++ b/support/intprops.h @@ -133,7 +133,8 @@ operators might not yield numerically correct answers due to arithmetic overflow. They do not rely on undefined or implementation-defined behavior. Their implementations are simple - and straightforward, but they are a bit harder to use than the + and straightforward, but they are harder to use and may be less + efficient than the INT_<op>_WRAPV, INT_<op>_OK, and INT_<op>_OVERFLOW macros described below. Example usage: @@ -158,6 +159,9 @@ must have minimum value MIN and maximum MAX. Unsigned types should use a zero MIN of the proper type. + Because all arguments are subject to integer promotions, these + macros typically do not work on types narrower than 'int'. + These macros are tuned for constant MIN and MAX. For commutative operations such as A + B, they are also tuned for constant B. */ @@ -339,9 +343,15 @@ arguments should not have side effects. The WRAPV macros are not constant expressions. They support only - +, binary -, and *. Because the WRAPV macros convert the result, - they report overflow in different circumstances than the OVERFLOW - macros do. + +, binary -, and *. + + Because the WRAPV macros convert the result, they report overflow + in different circumstances than the OVERFLOW macros do. For + example, in the typical case with 16-bit 'short' and 32-bit 'int', + if A, B and R are all of type 'short' then INT_ADD_OVERFLOW (A, B) + returns false because the addition cannot overflow after A and B + are converted to 'int', whereas INT_ADD_WRAPV (A, B, &R) returns + true or false depending on whether the sum fits into 'short'. These macros are tuned for their last input argument being a constant. |