其中一個建議是使用其他類型。
下面是整數類型,大小和限制的列表。
--------------------------------------------------------------------------------------
|type |size (B)|Limits |
--------------------------------------------------------------------------------------
|long long |8 |–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807|
--------------------------------------------------------------------------------------
|unsigned long long |8 |0 to 18,446,744,073,709,551,615 |
--------------------------------------------------------------------------------------
|int |4 |–2,147,483,648 to 2,147,483,647 |
--------------------------------------------------------------------------------------
|unsigned int |4 |0 to 4,294,967,295 |
--------------------------------------------------------------------------------------
|short |2 |–32,768 to 32,767 |
--------------------------------------------------------------------------------------
|unsigned short |2 |0 to 65,535 |
--------------------------------------------------------------------------------------
|char |1 |–128 to 127 |
--------------------------------------------------------------------------------------
|unsigned char |1 |0 to 255 |
--------------------------------------------------------------------------------------
注意long
和int
通常是相同的尺寸。
注那些限度不是在所有體系相同的非標準保證只有兩件事約可變大小:
- 1 =
sizeof(char)
= sizeof(unsigned char)
- 2 =
sizeof(shor)
= sizeof(unsigned short)
< = sizeof(int)
= sizeof(unsigned int)
< = sizeof(long)
= sizeof(unsigned long)
< = sizeof(long long)
= sizeof(unsigned long long)
另一種選擇是使用bigint庫,但是在這種情況下,計算將需要更多的時間,但將適合。
來源
2013-10-09 12:32:45
ST3
聽起來像整數溢出。 – john
有趣的是,在這個唯一相當大的數字是ret-val,一個「長雙」。所有其他的都是普通的'int'值。我認爲這是試圖解決這個問題,約翰和H2CO3都正確識別,順便說一句。 – WhozCraig