
?正在進行中?
將單包標頭文件下載到您的包含路徑下的位置。然後在您的代碼中#include :
# include " BigInt.hpp " // the actual path may vary創建BigInt類的對象,然後做您必須做的事情!
BigInt big1 = 1234567890 , big2;
big2 = " 9876543210123456789098765432101234567890 " ;
std::cout << big1 * big2 * 123456 << " n " ;
// Output: 1505331490682966620443288524512589666204282352096057600 =第二個操作數可以是BigInt ,一個整數( long long )或字符串( std::string或字符串字面)。
big1 = 1234567890 ;
big1 = " 123456789012345678901234567890 " ;
big1 = big2;+ , - big1 = +big2; // doesn't return the absolute value
big1 = -big2;+ , - , * , / , %其中一個操作數必須是一個BigInt ,另一個可以是BigInt ,一個整數( long long )或字符串( std::string或字符串字面)。
big1 = big2 + 1234567890 ;
big1 = big2 - " 123456789012345678901234567890 " ;
big1 = big2 * big3;
big1 = 1234567890 / big2;
big1 = " 123456789012345678901234567890 " % big2;+= , -= , *= , /= , %=第二個操作數可以是BigInt ,一個整數( long long )或字符串( std::string或字符串字面)。
big1 += big2;
big1 -= 1234567890 ;
big1 *= " 123456789012345678901234567890 " ;
big1 /= big2;
big1 %= 1234567890 ;++ , -- big1 = ++big2; // pre-increment
big1 = --big2; // pre-decrement
big1 = big2++; // post-increment
big1 = big2--; // post-decrement < , > , <= , >= , == , !=其中一個操作數必須是一個BigInt ,另一個可以是BigInt ,一個整數( long long )或字符串( std::string或字符串字面)。
if (big1 < 1234567890
or big1 > " 123456789012345678901234567890 "
or big1 <= big2
or 1234567890 >= big1
or " 123456789012345678901234567890 " == big1
or big1 != big3) {
...
}<< , >> std::cout << big1 << " , " << big2 << " n " ;
output_file << big1 << " , " << big2 << " n " ;
std::cin >> big1 >> big2;
input_file >> big1 >> big2;to_string , to_int , to_long , to_long_long將BigInt轉換為string , int , long或long long 。
注意:如果BigInt超出了目標類型的範圍,則會引發一個OUT_OF_RANGE異常。
some_str = big1.to_string();
some_int = big1.to_int();
some_long = big1.to_long();
some_long_long = big1.to_long_long();abs獲取BigInt的絕對價值。
big1 = abs(big2);big_pow10獲得等於10 exp的BigInt 。
big1 = big_pow10( 5000 ); // big1 = 10^5000 gcd獲得兩個BigInt s的最大共同分裂(aka。hcf)。其中一個參數可以是整數( long long )或字符串( std::string或字符串字面)。
big1 = gcd(big2, big3);
big1 = gcd(big2, 1234567890 );
big1 = gcd(big2, " 123456789012345678901234567890 " );
big1 = gcd( 1234567890 , big2);
big1 = gcd( " 123456789012345678901234567890 " , big2);lcm獲得兩個BigInt s的最小常見倍數(LCM)。其中一個參數可以是整數( long long )或字符串( std::string或字符串字面)。
big1 = lcm(big2, big3);
big1 = lcm(big2, 1234567890 );
big1 = lcm(big2, " 123456789012345678901234567890 " );
big1 = lcm( 1234567890 , big2);
big1 = lcm( " 123456789012345678901234567890 " , big2);pow將基本經驗值作為BigInt的價值。底座可以是一個BigInt ,一個整數( long long )或字符串( std::string或字符串字面)。
big1 = pow(big2, 789 );
big1 = pow( 987654321LL , 456 ); // suffix literal with LL to prevent conflicts
big1 = pow( " 1234567890 " , 123 );sqrt獲取BigInt的整數平方根。
big1 = sqrt(big2);big_random獲取一個隨機的BigInt ,即具有隨機數字(最多1000個)或特定數量的數字數字。
// get a random BigInt that has a random number of digits (up to 1000):
big1 = big_random();
// get a random BigInt that has 12345 digits:
big1 = big_random( 12345 );由於該項目是作為僅標題庫的構建的,因此沒有源文件。但是,每個標頭文件都有將項目分為單位測試。這些可以通過命令行進行編譯和構建,也可以使用對Cmake直接支持的IDE(例如CLION,QT創建者),也可以使用CMake可以生成項目文件(Visual Studio,Eclipse CDT,Code :: Blocks等)的IDE。
在Linux和MacOS上,您可以使用項目根目錄中的命令行來編譯和運行測試。
make 。make test 。make release 。生成的文件將出現在release文件夾中。Settings > Build > CMake中找到,請設置build的Generation path 。然後,您只需選擇要構建/運行的目標(單位測試),其餘的IDE將完成。
如果您的IDE不直接支持CMAKE,則需要通過命令行運行cmake ,並帶有適當的標誌來為您的IDE生成項目文件。嘗試一下,不應該很難!
請閱讀有關如何為該項目貢獻的詳細信息的貢獻指南。
該項目是根據MIT許可證的條款獲得許可的。