Work with fractions and irrational numbers.

Hello everybody, I'm new to this site and to the C++ world, and I need your help.
I'm looking for a library that handles rational, irrational and trascendental numbers and calculates the exact results without approximating values.
For example, if I want to calculate:
a = pi;
b = 3;
c = 2;

I want this library to return the result in this way:
sqrt(b*c)*a == sqrt(6)*pi

instead of
sqrt(b*c)*a == 7.6952989

In case it matters, I'm working on Ubuntu and I compile with g++.
You can ask me anything if I didn't explain everything clearly (english isn't my first language)

I'm pretty sure a library like that exists because it's too useful, I researched it but couldn't find anything.
Thank you very much :)
Last edited on
Wow, for a non-native speaker, you're the best I've seen on this site! As for the library that you're looking for, I think the Boost Library might offer it.. I am not familiar with it though... Here's the link: Good luck!

- Kyle
Last edited on
I don't think its possible
c and b are presumably integer types so they are 'exact' numbers.
Even though b*c is 'exact' (6) the sqrt(b*c) is an approximation.
Likewise pi to a billion decimal places is still an approximation
That's what I'm talking about, i want something that returns √(6) ∏ instead of 7.6952989

I took a look to this "Boost Library" but it doesn't seem to do what I'm looking for.
You need a computer algebra system, this one is available free (should be a ubuntu deb available)

This is nothing to do with C++. If you want to write your own algebra system - good luck!
Topic archived. No new replies allowed.