-* Below are implementations of the four basic arithmetic operations
-* for `BigUnsigned's. Their purpose is to use a mechanism that can
-* calculate the sum, difference, product, and quotient/remainder of
-* two individual blocks in order to calculate the sum, difference,
-* product, and quotient/remainder of two multi-block BigUnsigned
-* numbers.
-*
-* As alluded to in the comment before class `BigUnsigned',
-* these algorithms bear a remarkable similarity (in purpose, if
-* not in implementation) to the way humans operate on big numbers.
-* The built-in `+', `-', `*', `/' and `%' operators are analogous
-* to elementary-school ``math facts'' and ``times tables''; the
-* four routines below are analogous to ``long division'' and its
-* relatives. (Only a computer can ``memorize'' a times table with
-* 18446744073709551616 entries! (For 32-bit blocks.))
-*
-* The discovery of these four algorithms, called the ``classical
-* algorithms'', marked the beginning of the study of computer science.
-* See Section 4.3.1 of Knuth's ``The Art of Computer Programming''.
-*/
+ * Below are implementations of the four basic arithmetic operations
+ * for `BigUnsigned's. Their purpose is to use a mechanism that can
+ * calculate the sum, difference, product, and quotient/remainder of
+ * two individual blocks in order to calculate the sum, difference,
+ * product, and quotient/remainder of two multi-block BigUnsigned
+ * numbers.
+ *
+ * As alluded to in the comment before class `BigUnsigned',
+ * these algorithms bear a remarkable similarity (in purpose, if
+ * not in implementation) to the way humans operate on big numbers.
+ * The built-in `+', `-', `*', `/' and `%' operators are analogous
+ * to elementary-school ``math facts'' and ``times tables''; the
+ * four routines below are analogous to ``long division'' and its
+ * relatives. (Only a computer can ``memorize'' a times table with
+ * 18446744073709551616 entries! (For 32-bit blocks.))
+ *
+ * The discovery of these four algorithms, called the ``classical
+ * algorithms'', marked the beginning of the study of computer science.
+ * See Section 4.3.1 of Knuth's ``The Art of Computer Programming''.
+ */
+
+/*
+ * On most calls to put-here operations, it's safe to read the inputs little by
+ * little and write the outputs little by little. However, if one of the
+ * inputs is coming from the same variable into which the output is to be
+ * stored (an "aliased" call), we risk overwriting the input before we read it.
+ * In this case, we first compute the result into a temporary BigUnsigned
+ * variable and then copy it into the requested output variable *this.
+ * Each put-here operation uses the DTRT_ALIASED macro (Do The Right Thing on
+ * aliased calls) to generate code for this check.
+ *
+ * I adopted this approach on 2007.02.13 (see Assignment Operators in
+ * BigUnsigned.hh). Before then, put-here operations rejected aliased calls
+ * with an exception. I think doing the right thing is better.
+ *
+ * Some of the put-here operations can probably handle aliased calls safely
+ * without the extra copy because (for example) they process blocks strictly
+ * right-to-left. At some point I might determine which ones don't need the
+ * copy, but my reasoning would need to be verified very carefully. For now
+ * I'll leave in the copy.
+ */
+#define DTRT_ALIASED(cond, op) \
+ if (cond) { \
+ BigUnsigned tmpThis; \
+ tmpThis.op; \
+ *this = tmpThis; \
+ return; \
+ }