- cmake >= 3.12
- gnu gcc 5+/clang 5+/msvc
- make
- GMP or MPIR
- mpdecimal
Namespace for all things is bigmath
Arbitrary precision decimal numbers:
#include <bigmath/bigdecimal.h>
#include <bigmath/bigint.h>
void do_something() {
bigmath::bigdecimal val("124.450200000000000200");
bigmath::bigdecimal base("1000000000000000000");
bigmath::bigdecimal res = val * base;
bigmath::bigint = res.to_bigint();
// just output as-is
std::cout << res << std::endl;
// output with only 6 digits after point (format string has Python syntax)
std::cout << res.format(".6f") << std::endl;
// convert decimal to bigint (drops everything after point)
std::cout << res.to_bigint() << std::endl;
}
Add remote:
conan remote add edwardstock https://edwardstock.jfrog.io/artifactory/api/conan/conan
conan install <path/to/your/project> bigmath/1.0.4@edwardstock/latest
or using conanfile.txt
[requires]
bigmath/1.0.8@edwardstock/latest
[generators]
cmake
Supported distributions:
- centos 7, 8
- fedora 32-34
Steps:
- Create
edwardstock.repo
file inside/etc/yum.repos.d
- Add below to this file
[edwardstock]
name = edwardstock
baseurl = https://edwardstock.jfrog.io/artifactory/rhel/[centos or fedora]/\$releasever/\$basearch
enabled = 1
gpgcheck = 0
gpgkey = https://edwardstock.jfrog.io/artifactory/rhel/[centos or fedora]/\$releasever/\$basearch/repodata/repomd.xml.key
repo_gpgcheck = 1
- Update repository
yum -y update
ordnf update
- Install lib
yum install bigmath-devel
Supported distributions:
- debian: stretch, buster
- ubuntu: xenial, bionic, focal, groovy
echo "deb https://edwardstock.jfrog.io/artifactory/debian $(lsb_release -c -s) main" | sudo tee -a /etc/apt/sources.list
curl -s https://edwardstock.jfrog.io/artifactory/api/gpg/key/public | sudo apt-key add -
apt update && apt install libbigmath-dev
-
Add submodule or just clone
git submodule add https://github.com/edwardstock/bigmath.git /path/to/libs/bigmath
git clone https://github.com/edwardstock/bigmath.git /path/to/libs/bigmath
-
Edit
CMakeLists.txt
:
# your executable or library
add_executable(my_executable)
#or if library
add_library(my_library)
# include module
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/path/to/libs/bigmath)
# link with your project
target_link_libraries(my_[executable|library] bigmath)
This library requires to be built
If you have conan, then just build, dependencies automatically will be installed and build (if required)
git clone https://github.com/edwardstock/bigmath.git bigmath && mkdir -p build && cd bigmath/build
cmake --build . --target install
If you DON'T have conan, then you have to install dependencies by yourself:
- libgmp or libmpir
- mpdecimal (source link is on the top of readme)
git clone https://github.com/edwardstock/bigmath.git bigmath && mkdir -p build && cd bigmath/build
cmake .. -DCMAKE_BUILD_TYPE=Release -DENABLE_CONAN=Off
cmake --build . --target install
git clone https://github.com/edwardstock/bigmath.git bigmath && mkdir -p build && cd bigmath/build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DENABLE_TEST=On
cmake --build . --target bigmath-test
./bin/bigmath-test