|
Boost : |
Subject: Re: [boost] [Review:Algorithms] Order of args to clamp
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-09-27 13:22:07
Marshall Clow wrote:
>
> A couple of interesting results that I found playing around
> this morning
>
> namespace ba = boost::algorithm;
>
> short foo = 50;
> BOOST_CHECK_EQUAL(56, ba::clamp(foo, 56.9, 129));
> BOOST_CHECK_EQUAL(24910, ba::clamp(foo, 12345678,
> 123456999 ));
This is why warnings should not be ignored, of course. Mixing floating point and integer types is always worth care, so the first one can just be chalked up to carelessness. Still, it might be worth the trouble to disallow the combination, forcing the caller to do the rounding as appropriate. (Integer limits for a floating pointer value are not a problem aside from the usual inexactness of floating point types.)
Truncation, as in your second example, is more irksome. It would be very nice if range checks could be included, provided an appropriate manifest constant was defined. I can imagine a commercial standard library adding that to a "checked" build as a QoI feature, at least.
_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
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