TinyFractionsPP

Precise fraction math for C++ — no decimal drift, no rounding errors. Built for mathematicians, physicists, and engineers who demand accuracy.

View on GitHub

Why TinyFractionsPP?

Floating-point arithmetic is fast but imprecise. TinyFractionsPP keeps your numbers as exact fractions — preserving every digit through multiplication, division, and exponentiation. Perfect for scientific computing, physics simulations, and any project where precision matters.

Create fractions from integers, doubles, or even other fractions. Compare, add, subtract, multiply, divide, and raise to a power — all without losing accuracy to decimal conversion.

Install

Clone this repository by https or ssh:

git clone https://github.com/awsederpash-coder/TinyFractionsPP.git git clone git@github.com:awsederpash-coder/TinyFractionsPP.git сd TinyFractionsPP

Configure:

cmake -B build -DCMAKE_BUILD_TYPE=Release

And build:

cmake --build build --target install

In CMakeLists.txt at your project insert:

find_package(TinyFractionsPP 0.2 REQUIRED) add_executable(my_program main.cpp) target_link_libraries(my_program PRIVATE TinyFractionsPP::TinyFractionsPP)

Now it's easy to import my library from any source file:

#include <TinyFractions/Core.h>

Usage

All methods and classes are int namespace fr.

Fractions class: fr::CommonFraction.

Constructors:

  • (int64,int64)
  • (int64)
  • (double,double)
  • (double)
  • (CommonFraction, CommonFraction)

Methods:

  • print(string start, string end) → void
  • getFull() → pair(int64,int64)
  • getNumerator() → int64
  • getDenominator() → unsigned int64
  • getDecimal() → double

Functions:

  • fr::power(fr::CommonFraction, int) → fr::CommonFraction
  • fr::bring(fr::CommonFraction, fr::CommonFraction) → pair<CommonFraction,CommonFraction>

Operators:

  • +
  • -
  • *
  • /

Comparison and arithmetic operators work between fractions as well as with int and double.

using cfr = fr::CommonFraction; using int64 = long long; using uint64 = unsigned long long; int main() { cfr fr1(3,5); cfr fr2(-0.7); cfr fr3(fr1,fr2); (cfr1*cf2).print("Res1: ","\n"); (cfr1+cf3).print("Res2: ","\n"); (cfr1-cf2).print("Res3: ","\n"); fr::power(fr2,3).print("Res4: ","\n"); return 0; }

License

Apache2.0 © Apache Software Foundation