??????Щ?????????????????????e??????????????std::abs???????????????????????????????????????С?????int???????????????????????磺

int min_int = -2147483648;
cout<

????????????????-2147483648????????????п????????????????????????????????????

????1????????汾??

unsigned int __abs(int value)
{
    return (value >= 0) ? value : -value;
}

?????????std::abs????·?????????

????2????????汾??

#include

unsigned int __abs(int value)
{
    return (std::numeric_limits::min() == value || value >= 0) ? value : -value;
}

????????汾?????????????????std::numeric_limits::min()??????????int???С???????????int???????????????????value??С??int???????value????????????????????λ??λ?????——???unsigned int??з???λ????????????е????value???С?????????????????????ɡ?

??????????汾???????????????ж????????????????????????????

????3?????????汾??

unsigned int __abs(int value)
{
    unsigned int copyed_value = value;
    return (copyed_value > 0x80000000) ? -value : copyed_value;
}

???????32λ??С??int??0x80000000——??λ????λ?1????λ??λ??????unsigned int????????????????????????????????λ?1??????λ????????????-1??16?????????0x80000001????????????????λ??λ?????????copyed_value?С???????????ж??????

??????1?????copyed_value?????0x80000000??????value?????????????????????????-value????

??????2?????copyed_value?????0x80000000??????value?????С??????????????λ??λ??????copyed_value?д?????value????????????copyed_value??

??????3?????copyed_value??С??0x80000000?????value???????????alue????copyed_value???ɡ?

????????????????????2?????3??????????????copyed_value??????????????????????????α???????????????????Ρ??????????????????????????????????á?

????????????????????????????????????????????????????????????????Сint?????????????std::abs????????????????????????????????????????????????????????????????Сint?????????????????????????????????????????

??????????????????????????????????????治??????????????????У???????????????????ú?????