<wi*@seed.net.tw> wrote:
osmium wrote:...
Why not do the obvious? Perhaps I don't understand what your problem is.
template<typename T>
T negate(T t) {
if(t==std::numeric_limits<T>::min()) {
throw error;
}
return -t;
}
1. I find no document clearly states when negate a value t yields
valid result or not.
2. The above method won't work for some machine not Intel CPU.
Are you implying that there is a compiler that lies about the value of
INT_MAX and/or INT_MIN in <climits>? I based what I said on the assumption
that they told the truth. I didn't look at your code; examining the
variables such as those two are what I had in mind. If you want an
alternative, you might be able to use one of the abs() functions somehow. I
have nothing else to offer.