Could SWI-Prolog have or need decimals?

I noticed that I am currently facinated by decimals. So
not to polute the other thread, here a collection what came
to my mind so far, and what I could find:

In Java they mainly bundle the Java class BigDecimal because
of their java.sql JDBC adapter. The class delivers CR_XXX
functionality, you have a couple of rounding modes available,

and can do arithmetic just like crlibm. Whats not provided
is trigonometry etc… i.e. functions above the basic operations.
It has also a flexible mode for some basic operations, where no

precision needs to be specified, and where precision can grow,
like for example these two rules, I have sketeched them a little
simplfied, since for addition the place of the period is also important:

``````precision(a+b) = max(precision(a), precision(b))
precision(a*b) = precision(a)+precision(b)
``````

Having binary p=52 not fixed requires possibly a slightly different
mindset
. What should the architectual decision be? Some new
flag for the precision? What if a database row has columns from

a diversity of precisions? Anyway its amazing, that the most demand
for flexible precision comes from the commercial domain, and not
from some computation in physics, chemistry, etc…

Edit 22.10.2022
BTW: Here you see an alternative to rational/1. It is based
on the observation that 1/2^n has a finite decimal expansion.
You can check yourself, it grows more and more but you can

prove that it terminates for each n:

``````?- between(1,5,N), X is 1/2^N, write(N), write(': '),
write(X), nl, fail; true.
1: 0.5
2: 0.25
3: 0.125
4: 0.0625
5: 0.03125
true.
``````

So you can use this to convert a binary floating point value into
a decimal, and this conversion is exact, just like the rational
conversion. Here you see two binary floating point values near

to each other, exactly decimal expanded to their maximum
needed digits to identify them in a decimal system, after
this expansion, digits going farther than what is shown,

only zeros in the digits:

``````/* Binary Floating Point Value from f64 */
?- X is decimal(1.4262129449486016).
X = 0d1.42621294494860162416216553538106381893157958984375.

?- X is decimal(1.4262129449486018).
X = 0d1.4262129449486018462067704604123719036579132080078125.
``````

Problem is you cannot convert rational numbers like this,
there is no way rational to radix=10 always. But you have a bridge