c++ exact ratio arithmetic; constexpr.
  • C++ 91.1%
  • CMake 8.9%
Find a file
Roland Conybeare 529e2b25b8 Split 'xo-reader2/' into commit '70943b8e08'
git-subtree-dir: xo-reader2
git-subtree-mainline: 9853180ffdb7d79161770582e2add491775bca63
git-subtree-split: 70943b8e08
2026-05-31 00:15:05 -04:00
.github/workflows xo-ratio: github: + missing randomgen dep in xo-cpp-builder workflow 2024-04-23 20:19:45 -04:00
cmake xo-cmake: setup to make share target available via cmake install 2026-02-27 19:38:53 +11:00
docs xo-ratio: build: streamline docs+utest setup 2024-04-25 18:15:24 -04:00
example xo-ratio: build fix for indentlog dep + install examples 2025-09-22 12:30:23 -04:00
include/xo/ratio xo-ratio: compiler nit 2025-08-23 13:09:39 -04:00
utest xo-ratio: utest: APPL carveout for reflected types in ratio utest 2026-01-16 21:07:27 -05:00
.gitignore xo-ratio: streamline example+utest build 2024-05-30 16:36:20 -04:00
CMakeLists.txt xo-ratio: build fix for indentlog dep + install examples 2025-09-22 12:30:23 -04:00
LICENSE xo-ratio: initial commit 2024-04-17 21:23:20 -04:00
README.md xo-ratio: update README.md for xo-build 2024-09-14 10:55:31 -05:00

ratio library

Header-only, constexpr library providing exact representation for rational numbers.

Relative to std::ratio:

  1. Uses constexpr instead of creating new types. This means it can be used seamlessly at runtime.
  2. Supports a few more arithmetic operations, for example exponentiation to integer powers.
  3. Provides constexpr conversion to fixed-capacity strings (using xo-flatstring)
  4. Provides concept support (with c++20)
  5. Requires modern (c++17) support to achieve this

Relative to boost::ratio:

  1. Streamlined, assumes modern compiler support

Documentation

Getting Started

install dependencies

copy repository locally

Using xo-build (provided by xo-cmake):

$ xo-build --clone xo-ratio`

or equivalently:

$ cd ~/proj   # for example
$ git clone https://github.com/Rconybea/xo-ratio

build + install

Using xo-build:

$ xo-build --configure --build --install xo-ratio

or equivalently:

$ PREFIX=/usr/local # for example
$ BUILDDIR=.build   # for example
$ mkdir xo-ratio/${BUILDDIR}
$ cmake -DCMAKE_INSTALL_PREFIX=${PREFIX} -S xo-ratio -B xo-ratio/${BUILDDIR}
$ cmake --build xo-ratio/${BUILDDIR}
$ cmake --install xo-ratio/${BUILDDIR}

build with unit test coverage

$ cd xo-ratio
$ mkdir .build-ccov
$ cmake -DCMAKE_BUILD_TYPE=coverage -B .build-ccov
$ cmake --build .build-ccov

run coverage-enabled unit tests

$ cmake --build .build-ccov -- test

generate html+text coverage report

$ cmake --build .build-ccov -- ccov

browse to .build-ccov/ccov/html/index.html

LSP support

$ cd xo-ratio
$ ln -s .build/compile_commands.json