All Projects → pr0crustes → BigNumber

pr0crustes / BigNumber

Licence: MIT license
A really long long long long long long number in C++

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to BigNumber

klibcpp
kedixa's Cplusplus Library(timer, multiarray, unsigned_bigint, bigint, rational)
Stars: ✭ 17 (-54.05%)
Mutual labels:  biginteger, bigint, bignumber
bigint
bigint is a C++ library which can handle Very very Big Integers. It can calculate factorial of 1000000... it can go any big. It may be useful in Competitive Coding and Scientific Calculations which deals with very very large Integers. It can also be used in Decryption process. It has many inbuilt functions which can be very useful.
Stars: ✭ 34 (-8.11%)
Mutual labels:  biginteger, bigint, biginteger-cpp
BigInteger
Be limited not by the size of your register but by the bulk of your RAM.
Stars: ✭ 13 (-64.86%)
Mutual labels:  biginteger, bigint, bignumber
as-bignum
Fixed length big numbers for AssemblyScript 🚀
Stars: ✭ 49 (+32.43%)
Mutual labels:  biginteger, bigint
BhimIntegers
BhimIntegers🚀 is a C++ library that is useful when we are dealing with BigIntegers💥💥. We can handle big integers (integers having a size bigger than the long long int data type) and we can perform arithmetic operations📘 like addition, multiplication, subtraction, division, equality check, etc📐📐. Also, there are several functions like factorial, …
Stars: ✭ 43 (+16.22%)
Mutual labels:  biginteger, bignumber
Base62
PHP Base62 encoder and decoder for integers and big integers with Laravel 5 support.
Stars: ✭ 16 (-56.76%)
Mutual labels:  biginteger, bigint
break infinity.js
A replacement for decimal.js for incremental games who want to deal with very large numbers (bigger in magnitude than 1e308, up to as much as 1e(9e15) ) and want to prioritize speed over accuracy.
Stars: ✭ 145 (+291.89%)
Mutual labels:  biginteger, bignumber
swift-numberkit
Advanced numeric data types for Swift 5, including BigInt, Rational, and Complex numbers.
Stars: ✭ 47 (+27.03%)
Mutual labels:  biginteger, bigint
UInt256
An UInt256 library written in Swift 4
Stars: ✭ 20 (-45.95%)
Mutual labels:  biginteger, bigint
nein-math
NeinMath is playing around with arbitrary precision integers, written in pure managed code, not using any unsafe stuff, and a bit faster than the build-in .NET type for integers with a few thousand bits.
Stars: ✭ 14 (-62.16%)
Mutual labels:  biginteger, bignumber
id-mask
IDMask is a Java library for masking internal ids (e.g. from your DB) when they need to be published to hide their actual value and to prevent forging. It has support optional randomisation has a wide support for various Java types including long, UUID and BigInteger. This library bases its security on strong cryptographic primitives.
Stars: ✭ 39 (+5.41%)
Mutual labels:  biginteger
hebimath
arbitrary precision arithmetic library
Stars: ✭ 37 (+0%)
Mutual labels:  bignumber
Swift-MathEagle
A general math framework to make using math easy. Currently supports function solving and optimisation, matrix and vector algebra, complex numbers, big int, big frac, big rational, graphs and general handy extensions and functions.
Stars: ✭ 41 (+10.81%)
Mutual labels:  biginteger
VBCorLib
The VBCorLib framework brings many of the powerful .NET classes to VB6.
Stars: ✭ 81 (+118.92%)
Mutual labels:  biginteger
protobuf-ts
Protobuf and RPC for TypeScript
Stars: ✭ 527 (+1324.32%)
Mutual labels:  bigint
biginteger
A PHP library to work with big integers.
Stars: ✭ 19 (-48.65%)
Mutual labels:  biginteger
bytes-java
Bytes is a utility library that makes it easy to create, parse, transform, validate and convert byte arrays in Java. It supports endianness as well as immutability and mutability, so the caller may decide to favor performance.
Stars: ✭ 120 (+224.32%)
Mutual labels:  biginteger
DataTypes
Built-in data types
Stars: ✭ 34 (-8.11%)
Mutual labels:  bigint
evm-bn
Convert fixed-point numbers to ethers big numbers and vice-versa.
Stars: ✭ 33 (-10.81%)
Mutual labels:  bignumber
vallang
Generic immutable recursive data representation API targeted at source code models and more.
Stars: ✭ 28 (-24.32%)
Mutual labels:  biginteger

BigNumber

Overcome the integer limit.

WARNING: This lib is a work in progress made by an amateur in C++, and is probably not production ready. It was created as a personal project, mainly as a learning experience. This project is here pubished just in case anyone find any use out of it, or maybe want to learn with it.

Contents

Info

BigNumber is a header only library for working with integers values bigger than the hardware limit.
BigNumber has no addition dependencies and is as simple to use as possible.

Usage

Installing

Installation is very simple, just download and copy the BigNumber header to your project.
Then, you can simply include in other files:

#include "BigNumber.h"

or

#include "<some_folder>/BigNumber.h"

depending where you put the file.

Overview

For simplicity reasons, this overview will use using pr0crustes::BigNumber;. If you prefer not to do so, you can access the BigNumber class as pr0crustes::BigNumber.

Instantiation

It is possible to instantiate a BigNumber in multiple ways:

BigNumber A;  // will hold the value 0.
BigNumber B(100);  // B will hold the value 100.
BigNumber C(-50);  // C will hold the value -50.
BigNumber D("-4561273837128312881");  // D will hold the value -4561273837128312881.
BigNumber E = "4561273837";  // E will hold the value 4561273837
BigNumber F = 2;  // F will hold the value 2.
Operators

The BigNumber class overload the following operators: +, -, *, /, %.
Overloading these ones, others operators like +=, -=, *=, /=, %=, ++, --, - reuse the previous ones to also work.

BigNumber a("1390824942691875931654");
BigNumber b("373294235818098884803");

std::cout << (a + b) << std::endl;
// Output: 1764119178509974816457

std::cout << (a - b) << std::endl;
// Output: 1017530706873777046851

std::cout << (a * b) << std::endl;
// Output: 519186934138915001194112299224174047254162

std::cout << (a / b) << std::endl;
// Output: 3	(Divison ouput is rounded down)

std::cout << (a % b) << std::endl;
// Output: 270942235237579277245

Relational operators, like >, >=, <, <=, ==, != are also overloaded.

Interface
  • A BigNumber instance is printable, overloading <<, but you can also get it's std::string representation by calling .asString() in an instance.

  • Use .absoluteValue() to get a NEW instance of BigNumber with the absolute value of the instance called on.

  • Use .asBinary() to get a binary representation of the BigNumber. The first Bit indicates if it is negative or not.

  • Use .asLongLong() to get the value of an instance as a long long.

  • Use .divide10(int N) to quickly divide a bignumber by 10, N times.

  • Use .fitsInLongLong() to check if an instance can be safelly converted to a long long.

  • Use .fromBinary(std::string binary, bool isSigned) (static) to create a new instance from a binary string. By default, the first bit will be interpreted as a negative indicator. To supress it, pass false to the isSigned arg.

  • Use .isOdd() or .isEven() to check if an instance is Odd or Even.

  • Use .isPositive() to check if an instance is positive or not.

  • Use .isOne() to check if an instance is one (positive), faster than comparing to another object.

  • Use .isZero() to check if an instance is zero, faster than comparing to another object.

  • Use .lenght() to get the count of how many digits an instance has.

  • Use .modPow(BigNumber p, BigNumber m) to get the result of the module m of the instance to the power of p, this is (instance ^ p) % m. This is way faster than .pow() and should be used intead of doing instance.pow(p) % m.

  • Use .pow(BigNumber N) to get the result of the instance to the n power. This operation is expensive and can take a while with larger Ns. Use .modPow() if possible.

  • Use .times10(int N) to get a the result of the instace times 10 to the power of N, basically multiplying by 10 N times. This is faster than multiplying by 10.

  • Use BigNumber::randomBigNumber(int l) (static) to get a random BigNumber instance with l digits. THIS USES A PSEUDO-RANDOM FUNCTION. DO NOT RELY IN IT BEING COMPLETELY RANDOM.

  • Use BigNumber::randomBigNumberInRange(BigNumber l, BigNumber h) (static) to get a random BigNumber instance that will be >= l and < h. THIS USES A PSEUDO-RANDOM FUNCTION. DO NOT RELY IN IT BEING COMPLETELY RANDOM.

Randomness

All random functions are pseudo-random function.
Do not rely in it being completely random.
Although, using pseudo generation, the results seens to be uniform, as shows the graph.

Warning

A few methods will throw exceptions of type std::invalid_argument in case an invalid operation is attempted, like instantiating a BigNumber from a non-number string, dividing by 0, module operation by 0.
A few methods that do not support negative numbers will also throw exceptions when called with a negative number. This includes pow and mowPow with negative arguments.
Since this lib is open source, it is recommended that you read the comment above a method defition before using it in your code.

Contributing

Contributions are welcome, fork this repo, change it, open a pull request or an issue.
Make sure no tests are failing.

License

All code is licensed under MIT.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].