Skip to content
a single header library for representing rational number precisely in C++
C++ Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE
Makefile
README.md
demo.cpp
rational.h
test.cpp
unit_test.h

README.md

Rational Number in C++

Motivation

This library is for representing rational number precisely, in decimal or other positional system, such as binary form.

Quick Start

This library is released as single C++ header: rational.h

Here goes a very simple example:

#include "rational.h"
using namespace std;  // for 'rational'
using namespace math; // for 'cout' & 'endl'

int main()
{
    rational x(3, 5);
    cout << x.to_fraction() << endl;   // in fraction format: 3/5
    cout << x.to_decimal() << endl;    // in decimal format: 0.6
    cout << x.to_decimal<2>() << endl; // in binary decimal format: 0.(1001)...
    return 0;
}

There are more examples in demo.cpp

You can’t perform that action at this time.