
On 16 June 2010 06:57, Chad Nelson <chad.thecomfychair@gmail.com> wrote:
C: Throw an exception if any calculation results in a negative number. (Not very useful, but logical because under the built-in types' unsigned rules, a negative number in an unlimited-length library would be infinitely long.)
That results in look-before-you leap, which is probably bad for speed here, since the subtraction is similar in cost to the comparison. Though it does feel like the best option for operator--(), since there the look is cheap.
D: Force any negative numbers to a different value, such as zero or maybe their positive counterparts. (I can't think of any use for this, I just put it here for completeness.)
Force to zero is "saturation", which is a legitimate desire in certain situations, so it might not be as useless as you think. Making subtraction be absolute difference in an interesting option, since it at least keeps the a-b = 0 <=> a = b equivalence intact.
Can anyone think of a potential reason for options C or D? Or a reason to prefer option B? Or maybe come up with a different idea entirely?
How about this combo of B, C, and D: - if !i, --i and i-- both throw exceptions. - a - b doesn't compile for non-fixed length - provide a separate absdiff(a, b) function ~ Scott