From: Daniel Arndt Date: Mon, 30 Apr 2018 16:16:11 +0000 (+0200) Subject: Add documentation to nonoverflow_add X-Git-Tag: v9.0.0-rc1~57^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08791e8ccc47d8c353ca7e10ddfa669a8a8225f7;p=dealii.git Add documentation to nonoverflow_add --- diff --git a/tests/tests.h b/tests/tests.h index 910bbca72d..64ea510286 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -140,6 +140,22 @@ number get_real_assert_zero_imag(const number &a) // we put this into a namespace to not conflict with stdlib namespace Testing { + /** + * This function defines how to deal with signed overflow, which is undefined + * behavior otherwise, in sums. Since unsigned overflow is well-defined there + * is no reason to resort to this function. + * The way we want to define the overflow is the following: + * The value after the maximal value is the minimal one and the value + * before the minimal one is the maximal one. Hence, we have to distinguish + * three cases: + * 1. $a+b>max$: This can only happen if both @p a and @p b are positive. By + * adding $min-max-1$ we are mapping $max+n$ to $min+n-1$ for + * $n>1$. + * 2. $a+b1$. + * 3. $min<=a+b<=max$: No overflow. + */ template Number nonoverflow_add (Number a, Number b) {