Is there a generic way to promote all computations involving rationals into rationals in SWIPL?
In general, a mixed expression of rationals and floats will result in a float. And an expression in only rationals (including integers) will result in a rational as long as the prefer_rationals
environmental flag is true
.
Since rationals can become arbitrarily large in size there is a “tripwire” which triggers automatic conversion of rationals to floats when they become too large (see flag max_rational_size
).
Floats can be converted to rationals (see arithmetic functions rational/1
and rationalize/
). I don’t know of any system-defined way to do this automatically.
So assuming this is not news to you, can you elaborate on what you’re trying to do? Examples?