|
Boost : |
Subject: Re: [boost] [XInt] review
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-03-09 09:41:58
Chad Nelson wrote:
> Steven Watanabe <watanabesj_at_[hidden]> wrote:
>
> > Why can the comparison operators throw? I would have
> > expected that they could be implemented to never throw.
>
> So far as I know, the only reason they would ever throw is if
> they're passed a Not-a-Number value, or if something
> unpredictable has gone seriously wrong.
I would hope you could be more definitive than that and clearly document the behavior.
> > When you test for integer_t<BOOST_XINT_APARAMS>::Nothrow &&
> > n.is_nan(), you could just test n.is_nan() and make sure
> > that n.is_nan() is always false if Nothrow is true.
>
> Couldn't that prevent some less-intelligent compilers from
> optimizing out the test?
Only if is_nan() isn't inline or the optimizer is really stupid (in which case you shouldn't care because there will be many other failures to optimize).
> > magnitude_t:
> > * It probably needs to be POD for you to make assumptions
> > about the layout.
>
> The "struct hack" is a standard C idiom, and has been for as
> long as C has been around. It only became explicitly
> documented behavior in C99, but it works with all known C and
> C++ compilers; I checked very thoroughly, and even asked on
> this list (where one might reasonably expect to find people
> with experience with really odd architectures and compiler
> setups), and wasn't able to find a single report of a compiler
> where it would fail.
A C struct is POD.
> > gcd.hpp:
> > The behavior of invmod when the inverse doesn't exist is to
> > return zero. Wouldn't an exception/NaN be more consistant?
>
> I prefer to reserve exceptions for exceptional behavior,
> primarily errors. A number that doesn't have an inverse isn't
> really exceptional, there are many such values.
Returning NaN poisons subsequent calculations. Zero doesn't.
_____
Rob Stewart
Software Engineer, Core Software
Susquehanna International Group, LLP
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