C++???????????????
???????????? ???????[ 2012/9/14 10:26:15 ] ????????
??????Щ?????????????????????e??????????????std::abs???????????????????????????????????????С?????int???????????????????????磺
int min_int = -2147483648; cout< |
????1????????汾??
?????????std::abs????·?????????
????2????????汾??
#include
unsigned int __abs(int value)
????????汾?????????????????std::numeric_limits
??????????汾???????????????ж????????????????????????????
????3?????????汾??
???????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?????????????????????????????????????????
??????????????????????????????????????治??????????????????У???????????????????ú?????
unsigned int __abs(int value)
{
return (value >= 0) ? value : -value;
}
{
return (std::numeric_limits
}
unsigned int __abs(int value)
{
unsigned int copyed_value = value;
return (copyed_value > 0x80000000) ? -value : copyed_value;
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11