Skip to content

A simple header-only library for C++ to do fraction math.

License

Notifications You must be signed in to change notification settings

Winnak/fractions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fractions

A simple header-only library for C++ to do fraction math.

NOTE: Fractions are not reduced/minimized on arithmetic-operations, but are reduced on comparisons.

Usage:

Copy fractions.h into your project.

auto f1 = Fraction<int32_t, int32_t>{-3, 9};
printf("f1: %s\n", f1.to_string().c_str());
f1.reduce();
printf("f1-reduced: %s\n", f1.to_string().c_str());

auto f2 = frac32::from_float(0.5248f);
printf("f2: %s\n", f2.to_string().c_str());

Output:

f1: -3/9
f1-reduced: -1/3
f2: 328/625
f3: 6/21

(See tests/test.cpp for more)

License

MIT, see license file.

About

A simple header-only library for C++ to do fraction math.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages