# Promote to Rational

**URL:** https://swi-prolog.discourse.group/t/promote-to-rational/9055
**Category:** General
**Created:** [June 13, 2025, 9:26am UTC](https://swi-prolog.discourse.group/t/promote-to-rational/9055 "2025-06-13T09:26:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![gavin.mendel.gleason](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/gavin.mendel.gleason/32/207_2.png) [@gavin.mendel.gleason](https://swi-prolog.discourse.group/u/gavin.mendel.gleason)
#### Post date: [June 13, 2025, 9:26am UTC](https://swi-prolog.discourse.group/t/promote-to-rational/9055/1 "2025-06-13T09:26:42Z")

</div>

Is there a generic way to promote all computations involving rationals into rationals in SWIPL?

---

<div class="post-metadata">

### Author: ![ridgeworks](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ridgeworks/32/886_2.png) [@ridgeworks](https://swi-prolog.discourse.group/u/ridgeworks)
#### Post date: [June 13, 2025, 2:47pm UTC](https://swi-prolog.discourse.group/t/promote-to-rational/9055/2 "2025-06-13T14:47:31Z")

</div>

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?
