FWNX- about the abs function -

来源:互联网 发布:mac如何显示包内容 编辑:程序博客网 时间:2024/06/01 07:43

http://blog.csdn.net/soloist/article/details/153123

This article elaborate the the bug in VC.NET


Today I want to address it again:

in the 32-bit computer;

all the Deductive statements  are based on the following four facts: 

1 ==>  MIN_INT = 0x 8000 0000  = -2^31 =-2147483648

2==>max_int = 0x8fff ffff = 2^31 -1 = 2147483648;

3==>the abs(min_int) > abs(max_int)

4==>the max unsigned integer is 0x 7fff ffff = 2^32-1;


so when we use abs function to get a absolution of negative number

we must use unsigned int to get the return of the value;

becausethe absolute value of min_int of signed int is larger than the max_int of signed int;

but what is the value if we use int to receive the result ?


the result of -min_int is still min_int;


but for a max unsigned int it still works;


why 


so we should use the unsigned int to recieve the return value;


0 0
原创粉丝点击