Within GMP there's a submodule named "Mini GMP" which initializes, normalizes, clears, conanicalizes, set fields, compare, & finalizes `mpz_t` & `mpq_t` structures. And ofcourse there's mathematical operators. These are all straightforward with possibly a couple branches.
You can swap fields between 2 `mpq_t`s.
Convert to or from doubles involves a loop taking an exponent of a power-of-2. Or it can convert to/from strings.
The actual logic with most of the loops is implemented as macros.
1/2