Subject: Re: [boost] [xint] Design Question
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-06-17 07:21:59
Chad Nelson wrote:
> The options I've come up with so far, in order of my personal
> A: Make the unsigned option part of the fixed-length option, so it
> *can't* be specified separately. (The most elegant solution,
> but perhaps not the most useful.)
> B: Refuse to compile (or if I can't find a way to do that,
> instantiate) it, on the grounds that the combination can't
> logically be supported.
There are legitimate uses, I should think, so these options don't seem right.
> C: Throw an exception if any calculation results in a negative
> (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.)
As I replied to another post on this question, it appears the correct behavior is for negative results -- for subtraction, anyway -- to be impossible. That, of course, requires modulus behavior and your purpose, here, is to provide unlimited size, so there's no underflow possible.
I'm not certain that an exception is the most reasonable recourse, however. In code that never expects to produce negative results, even checking for a negative value is unwanted overhead. Wouldn't it be better to simply permit such an operation to result in memory exhaustion? That would get the attention of the program in short order without the tests and exception. You can also include checked modes -- a variation of a policy, perhaps -- that on negative values asserts, throws, etc. That would leave the choice to the client.
> 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.)
I think Scott suggested there was value in this scheme, so making the behavior a policy makes ever more sense.
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com
IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk