Giter Club home page Giter Club logo

apa's Introduction

APA : C++ big integers and dynamic precision floating points.

https://mrdcvlsc.github.io/APA

License: MIT build gcc-gnu clang mingw32

A C++ library for big integers and dynamic precision floating points (big numbers), pure c/c++ implementation, no handwritten inline-assembly.

Version 0.4.8 Status : [WIP - Work In Progress]

This branch (version 0.4.8) is an ongoing rewrite of the whole library.

Visit branch version 0.3.9 for the latest previous working version.


Links


Environment Requirements

Byte Order little-endian
OS Windows, Linux
Architecture x86, x64, x86-64
Compilers clang, GCC

If your system does not have these requirements, it might produce wrong results (on other system this could still work, but the chances of the tests failing will be higher).


Description

This is a C++ Arbitrary Precision Arithmetic library. Used to compute big integers and real numbers/floating point numbers. If you need to compute numbers that is greater than the max value of long long int, int64_t or __int128_t this library can do it for you.


About

This repository started as a personal hobby project not intended to replace big number libraries like boost multiprecision and gmplib and is only for didactic purposes. Though performance is still a priority, meaning this library will... as much as possible, use the fastest and the most efficient algorithms and implementations THAT THE AUTHOR(s) KNOW OF.

apa's People

Contributors

mrdcvlsc avatar nikkizuki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

apa's Issues

ubint increment and decrement

implementation for the increment and decrement operators of apa::ubint class.

  • ++ post-fix increment
  • ++ pre-fix increment
  • -- post-fix decrement
  • -- pre-fix decrement

code review issue

Yow, may iimprove pa tong function na to.. masmaganda to kung ipapasa yung input by reference at hindi na magreturn ng string. May copying kasi na nangyayari kapag pinass by value at nireturn by value kaya medyo ikakabagal ng program mo yun.

string BIGINT::removeFrontZeros(string input){
	bool stillzero = true;
	for(int i=0;i<input.size() and stillzero;++i){
		if(input[i]=='0' and input.size()!=1){
			input.erase(i,1);
			i=-1;
		}
		if(input[i]>='1' and input[i]<='9')
			stillzero = false;
	}
	return input;
}

parang ganito.


void BIGINT::removeFrontZeros(string& input){
	bool stillzero = true;
	for(int i=0;i<input.size() and stillzero;++i){
		if(input[i]=='0' and input.size()!=1){
			input.erase(i,1);
			i=-1;
		}
		if(input[i]>='1' and input[i]<='9')
			stillzero = false;
	}
}

Tapos pala, yung input.size() ay madaming beses mong tinawag. Isave mo nalang sa variable para bumilis konti.

	BIGINT(const char* value){
		string temp = "";
		for(long i = 0;value[i]!='\0';++i)
			temp = temp+value[i];
		check(temp);
		this->data = temp;
	}

Hindi mo na rin ata kailangan ng temp dito.. yung data na gamitin mo.. nakapass by reference naman yung check() eh.. at mukang hindi efficient yung pagconvert mo ng char* to string.. lalo na yung temp = temp + value[i].. suggest ko na gamitin mo na lang yung str() function.. str(value).. or try mo search ng masmabilis na paraan para maconvert yung char* to string..

int BIGINT::ones(int number, int tens){
	int ones = number-(tens*10);
	return ones;
}

int BIGINT::tens(int number){
	int tens = (int)floor((double)number/10);
	return tens;
}

masmabilis to kung ganto pre. parang same issue dun sa una kong comment.. as much as possible iwasan ang pagcopy. bukod sa sa concept ng copy at passing by reference, try mo din aralin yung concept ng const.

int BIGINT::tens const(const int& number){
	return  (int)floor((double)number/10);
}
	for(int i=0;i<n;++i)
		placeValueSums[i] = abs(placeValueSums[i]);

	string shiftedStringAnswer;
	for(int i=0;i<n;++i)
		shiftedStringAnswer.push_back(intToChar(placeValueSums[i]));

	if(!answerIsPositive)
		shiftedStringAnswer="-"+shiftedStringAnswer;

may paraan para masmabilis to. try mo sa isang loop lang.. at yung sa simula mo ilagay yung pag add nung negative sign.. sa pagconcat pala ng string masmaganda yung tmp += "x" kaysa sa tmp = tmp + "x"..

ubint bit shifts

implement right shift and left shift for apa::ubint class.

  • << left shift operator
  • >> right shift operator
  • <<= assignment left shift operator
  • >>= assignment right shift operator

ubint logical operators

implement the logical operators of apa::ubint class.

  • && logical and
  • || logical or
  • ! logical not

apa-configuration not working properly

  • The apa-base-configs.hpp header file is not working properly, the -D_FORCE_BASE2_XX flags passed to the compiler is also ignored.

This will be fixed in the future.

In the mean time, users can temporary fix this problem by deleting this line of code in the apa-base-configs.hpp:

#ifndef _APA_TESTING_PHASE
    #if defined(__SIZEOF_INT128__) || defined(UINT128MAX) || defined(_FORCE_BASE2_64)
        #define _BASE2_64
    #elif defined(UINT64_MAX) || defined(UINT64_WIDTH) || defined(_FORCE_BASE2_32)
        #define _BASE2_32
    #elif defined(UINT32_MAX) || defined(UINT32_WIDTH) || defined(_FORCE_BASE2_16)
        #define _BASE2_16
    #else
#error "ubint is not supported in this system."
    #endif
#endif

Then replace it with the following:

#ifndef _APA_TESTING_PHASE
    #if defined(_FORCE_BASE2_64)
        #define _BASE2_64
    #elif defined(_FORCE_BASE2_32)
        #define _BASE2_32
    #elif defined(_FORCE_BASE2_16) 
        #define _BASE2_16
    #elif defined(__SIZEOF_INT128__) || defined(UINT128MAX)
        #define _BASE2_64
    #elif defined(UINT64_MAX) || defined(UINT64_WIDTH)
        #define _BASE2_32
    #elif defined(UINT32_MAX) || defined(UINT32_WIDTH)
        #define _BASE2_16
    #else
#error "ubint is not supported in this system."
    #endif
#endif

ubint logical bitwise operator

implement the logical bitwise operators of apa::ubint class.

  • .boolean() method that returns true if the ubint instance is not zero.
  • & bitwise logical and
  • | bitwise logical or
  • ^ bitwise logical xor
  • &= assignment bitwise logical and
  • |= assignment bitwise logical or
  • ^= assignment bitwise logical xor
  • ~ bitwise logical not

ubint standard input and output

implement standard console input and standard output of ubint class

  • std::ostream& operator<<(std::ostream &out, const ubint &num) standard output
  • std::istream& operator<<(std::ostream &in, ubint &num) standard input

ubint relational operators

complete the implementation for relational operators of apa::ubint class.

  • != not-equal
  • > greater than
  • < less than
  • >= greater than equal
  • <= less than equal

use the ubint::compare function inside them.

ubint division and modulo

implementation for the division and modulo operators of apa::ubint class.

  • / division
  • /= division with assignment
  • % modulo
  • %= modulo with assignment

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.