Fraction Library
A C++ Fraction library.

Fraction Library Documentation

Version 1.2

Release Date: August 1, 2014

Download the Fraction Library: ZIP
Visit the Projects Page


The Fraction Library allows you to work with fractions (both improper and mixed) the same way integers are handled in C++. Perform arithmetic, comparison operations, I/O and others.

The Author

My name is Rafat Rashid. You can find more information about me at my website:


Installation is simple. Download the library and then unzip all the files into anywhere in your computer. However, do not change the directory hierarchy already set up.

The library was compiled using Microsoft Visual C++ 2010. If you are using some other IDE, such as Eclipse, Borland, XCode or even Linux and its Terminal, you may have to do some minor tweaking. For instance, create your own projects, include the appropriate source files and compile it. It is nothing an intermediate programmer can't handle.

In short, if you have a C++ compiler and have some experience in C/C++, you should be able to compile the library, regardless of the environment. If you are having trouble, shoot me an email.

Since I worked with all the IDEs and platforms mentioned above, I may include a step-by-step guide explaining what to do in each scenario at a later date.

Linking the Library to Your Project/Code

Skip this section if you will link the source files into your code base using a method of your own choosing.

The .lib (static library) files are located in the /lib directory. There are two versions, the one in "Debug" subdirectory and the other in "Release". Debug sets macros such as _DEBUG and other details that aid in debugging and testing your code. The Release version is the optimized version. Link one of these libraries into your own project to be able to use the Fraction Library. See the example projects in the /tests directory if you are unsure how to do this (see project properties).




The idea of creating a class to handle and manipulate fractions began in grade 12 in high school. I have found I learn by doing and besides, I enjoy programming. So on the summer of 2009, I thought I would pick up where I left off (I had to actually start from scratch as I no longer had the code I had written previously). Landing a job at UofT was also part of the motivation.

Version 1.0 and the predecessor of V.1.1 was released on June 28, 2009.

You can thank Johan Halmen (who contacted me a few months ago with some improvements I can make) for V.1.1.

In developing the Fraction Library, I utilized and built on a lot of tools I learned during my second year in university, including the use of Doxygen to document my code.

Bug Report

If you find any bugs in the library, please notify me by e-mail at Thanks. I am also active on facebook.

General comments and any suggestions on improvements I can make is also appreciated.


Thanks goes out to:

  • Dimitri van Heesch for Doxygen. Very impressive and versatile documentation tool.
  • Problem Solving with C++ 6th Edition (a textbook) written by Walter Savitch.
  • for being a quick reference for me.
  • Job at UofT which motivated me to learn how to make dynamic and static libraries.

Special thanks goes out to Johan Halmen for suggesting the Fraction::getGCD() algorithm. It's much better than what I had earlier.


The library is protected under the MIT license. For more information:

Change List

Version 1.2

Released August 1, 2014

  • Added MIT license and changelog.
  • Updated projects page link.

Version 1.1

Released March 25, 2011

  • Fraction::getGCD() method features Johan Halmen's algorithm for determining the Greatest Common Divisor of two numbers.
  • Fraction::sign is now a boolean instead of type char.
  • Fraction::setNum() now updates the numerator of the fraction properly.
  • Updated documentation for a better experience.

Version 1.0

Released June 28, 2010

  • Original Fraction Library.