Subject: [Boost-bugs] [Boost C++ Libraries] #9013: Create enum to make sign result more readable.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-08-18 16:28:55
#9013: Create enum to make sign result more readable.
-----------------------------------------------+-------------------------
Reporter: Joaquim Duran Comas <jduran.gm@â¦> | Owner: johnmaddock
Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: math
Version: Boost 1.54.0 | Severity: Cosmetic
Keywords: math, sign, enum type |
-----------------------------------------------+-------------------------
The function 'sign' return 1, 0 or -1 depending on the signal of the z,
but comparing the result with -1, 0 or 1 constants could make the source
code bad readable specially for people that doesn't know what the 'sign'
function return.
{{{
if (math::sign(value) == -1){
....
}
}}}
I propose to create an enumerate type to test the result of the function
with a constant, to create a more readable code. The compatibility with
the previous implementation of the function is not broken.
Suggested implementation of code:
{{{
enum Sign
{
SIGN_NEGATIVE = -1,
SIGN_ZERO = 0,
SIGN_POSITIVE = 1
}
template <class T>
inline Sign sign BOOST_NO_MACRO_EXPAND(const T& z)
{
return (z == 0) ? SIGN_ZERO : (boost::math::signbit)(z) ? SIGN_NEGATIVE
: SIGN_POSITIVE;
}
}}}
The previous example comparison could be write as:
{{{
if (math::sign(value) == math::SIGN_NEGATIVE){
....
}
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/9013> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:13 UTC