Skip to content

zyliutw/BigInteger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

BigInteger

Description

An Implementation of BigNumber library in C++
Develop with Xcode

Usage

Include

#include "BigNumber.hpp" 

Init

    BigNumber a {};
    BigNumber a {"12345"};
    BigNumber a {"-12345"};

Access

    BigNumber a {"-12345"};
    bool b = a.getSign(); // true
    string s = a.getNumber(); // "12345"
    string ss = a.getString(); // "-12345"
    string sss = string(a); //  "-12345"

    BigNumber b {};
    b.setSign("false");
    b.setNumber("999");
    string(b); // "999"

Operators

Equal
    BigNumber a {"11111"};
    BigNumber b = a;
    string(b); // "11111"
Add
    BigNumber a {"11111"};
    BigNumber b {"22222"};
    BigNumber c = a + b // "33333"

    BigNumber d = {"-33333"}
    BigNumber e = c + d; // "0"

    BigNumber k += e; 
Sub
    BigNumber a {"22222"};
    BigNumber b {"11111"};
    
    BigNumber c = a - b; // "11111"

    a -= b; // "11111"
Mul
    BigNumber a {"100"};
    BigNumber b {"100"};

    BigNumber c = a * b; // "10000"
    a *= b; // "10000"
Div
    CAN DIV NUMBER LARGE THAN "long long int"
    
    BigNumber a {"1000"};
    BigNumber b {"100"};

    BigNumber c = a / b; // "10"
    a /= b; // "10"
Mod
    CAN MOD NUMBER LARGE THAN "long long int"

    BigNumber a {"12"};
    BigNumber b {"5"};

    BigNumber c = a % b; // "2"
    a %= b; // "2"
Abs
    BigNumber d = {"-33333"};
    d.absolute();
    string(d); // 33333

    BigNumber e = {"-100"};
    BigNumber k = e.getAbsolute();
    string(k); // "100"
    string(e); // "-100"
Comparison
    BigNumber a {"11111"};
    BigNumber b {"22222"};

    if(a == b) // false
    if(a != b) // true
    if(a < b)  // true
    if(a <= b) // true
    if(a > b)  // false
    if(a >= b)  // false
    

Will do

  1. More operator
  2. Error Handler

Test

Use Catch

http://hiltmon.com/blog/2014/10/26/simple-c-plus-plus-testing-with-catch-in-xcode/
https://github.com/philsquared/Catch

Reference

https://github.com/panks/BigInteger

About

An Implementation of BigNumber library in C++

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages