Well forget about rational numbers for the moment and try
solving the problem for bigints first. Which is the topic for this
thread. The solution for bigints involves msb/1 and lsb/1.
And the variant 2 is the faster variant. In as far mpq_get_d_nearest
is also bad, Since it uses variant 1, this makes it a little slow, here
an annotation what is fast and what is slow:
Edit 25.09.2022
The lsb/1 can be used to determine HALF_EVEN rounding
in a border case. Basically the EVEN rule needs only
be applied if you have, i.e. all zeros:
/* Needs the EVEN rule */
x.5000000....
But if you find a 1 you can round up:
/* Doesn't need the EVEN rule */
x.50001001...
Imagine the period in “x.” determined from a bigint by shifting away
from msb/1 by some bits to determine the float mantissa in float(bigint).
But then the 1 can be far far away much more far away. You can
determine the 1 via lsb/1 and I guess its much faster than what
mpq_get_d_nearest does via divmod/4 essentially.