* Rolf Magnus:
> wrote:
>>
>> What is the protable way to negate an arithmetic integer?
>>
>> template<typename T>
>> T negate(T t) {
>> return -t; // <-- problem
>> }
>>
>> On my Intel machines, taking negation like the above is not
>> right if t is std::numeric_limits<T>::min()
>>
>> So the question may be reduced to: how to detect to throw an error.
>
> Hmm, you mean how to detect that t is equal to
> std::numeric_limits<T>::min()? Or did I miss anything?
He means, how to detect whether -std::numeric_limits<T>::min() exists.
Probably the most protable way to do that is to check whether
-(std::numeric_limits<T>::min()+1) == std::numeric_limits<T>::max().
Cheers.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?