Question

I'm doing some Linear programming exercises for the course of Algorithms, and in doing this I'm solving manually many operations with fractions. In doing this I realized that a human being don't suffer from numeric instability: we just keep values in fractional representation, and we finally evaluate (possibly by using a calculator) the value of expressions.

Is there any technique that does this automatically?

Im thinking of something which achieves some kind of symbolic computation, simplifies the numbers internally and finally yields the value only during the evaluation of an expression.

Was it helpful?

Solution

Boost contains a rational number library here which might be of help.

OTHER TIPS

In Python you can have a look at fractions:

import fractions
a = fractions.Fraction(2,3)

a*2
# Fraction(4, 3)

a**2
# Fraction(4, 9)

'Value: %.2f' % a
# 'Value: 0.67'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top