Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Vulgar fraction

Tags:

c++

variables

Is there a vulgar fraction that can be used as a variable?

For example: I want to divide the integers 1 and 3. The result as int is 0, as double result is 0,333333333. However, I want the result to be exactly 1/3, and later to use it in other equations in the program.

Is there a variable similar to the integer (int), decimal (double), e.t.c. (that is being declared and used in a similar way)? Or do I have to make one myself?

At first I was thinking how to make it myself, but I failed.

Thanks!

like image 759
AlexSavAlexandrov Avatar asked Nov 29 '22 16:11

AlexSavAlexandrov


1 Answers

Not in the core language, but there are libraries, such as boost::Rational.

like image 198
Pontus Gagge Avatar answered Dec 10 '22 13:12

Pontus Gagge