Skip to content

loveleif/Rational

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rational

A C++ implementation of a rational number. The template class Rational represents one rational number. It will always be simplified as far as possible, will always indicate sign on the numerator and will always represent 0 as 0/1. For example 2/-8 will be represented as -1/4 and 0/-128 will be represented as 0/1.

Some crude unit tests based on Visual Studios C++ unit test framework are supplied in the folder RationalTest.

Features:

  • Calculations are performed in a larger type than that of the Rational in use (see IntTraits.h). For example, the operation Rational<short> + Rational<short> will perform calculation steps with ints.
  • Construction and assignment from any integer type or Rational<IntType> type.
  • +=, -=, *=, /=, +, -, *, /, ==, !=, <, >, <=, >=, <<, >> operators
  • Postfix and prefix ++ and -- operators
  • int + Rational<IntType> will work as expected
  • Unary operator, r1 = -r2;
  • Explicit conversion to integer types

Build

This project has been built with Microsoft Visual Studio 2012, compiler Nov 2012 CTP, project files are included. It should however be easy to compile it using other C++11 compilers.

About

C++ implementation of a rational number.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published