Code Monkey home page Code Monkey logo

bigint's Introduction

BigInt

This is an implementation of big integers (size more than long or long long). It can store arbitrary size of integers. Uses linked list, and a base 10^17 number system.

To Compile: run 'make all'

The big integer is divided into different smaller parts each having 17 digits,starting from the LSB. I chose the number 17 because the maximum value that a 64 bit unsigned integer can hold is 2^64-1, which is a 20 digit number. Choosing 17 digits instead of 20 optimises on space and gives wiggle room to perform multiplication operations.

Each node of the linked list is viewed as a digit of the assumed number system. Below is the structure of linked list of numbers.

typedef struct digit9_tag{ unsigned long long int d; struct digit9_tag *next; } digit9;

Another structure, called bigInt, stores the actual number. It has a linked list of digit9's and a flag to indicate positive or negative value. The linked list stores the digit in reverse order, ie, number->LSB->..->MSB->NULL

Functions Available To The User:

enterbigint() ->

a function to take input from user. Available in iodata.h. The input is internally taken as a character array, which is parsed and the values are stored in a bigInt structure type variable and returned to the calling function.

printbigint(bigInt b) ->

a function to print the bigInt passed as parameter in appropriate format. Available in iodata.h. The function internally calls display() which is a recursive function to print the numbers from MSB to LSB.

Add(bigInt num1, bigInt num2) ->

a funtion to add the num1 and num2, bigInts passed as parameters, and return the sum. Available in addfunctions.h. The function adds each digit9 (node) of the linked list, and stores the carry of the result in a variable, and result of the addition in another linked list. Subttraction is also implemented by supplying negative sign of one of the operands. The resultant linked list is returned to the calling function.

Multiplication(bigInt num1, bigInt num2) ->

a function to multiply num1 and num2, bigInts passed as parameters to the function. Available in multfunctions.h. The functions calls a function NodexBigInt() which in turn calls NodexNode() which in turn calls enterformult(). The result of the multiplication is returned as a bigInt by the function.

Compare(bigInt num1, bigInt num2) ->

a function to compare num1 and num2. Available in bigIntLibrary.h. The function returns 0 if num1 == num2 -1 if num1<num2 1 if num1>num2

This is it for the explanation of this project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.