Can an Apfloat number be rationalized?
Closed this issue · 1 comments
axkr commented
There is a constructor for double
:
Aprational(double value)
is it also possible to have a constructor (or valueOf
method) which converts an approximate number Apfloat
to a "nearby" rational Aprational
?
Aprational(Apfloat value)
mtommila commented
Somebody once suggested this (by email)
Basically, the algorithm is to calculate the continued fraction for the given Apfloat and then take the n:th convergent to get a rational approximation of the floating-point number (the bigger the n, the better the approximation)
The corresponding function in Mathematica is Convergents
It currently isn't implemented in the apfloat library but I suppose it shouldn't be that hard to implement