MATLAB: High precision rational fraction approximation

high precisionrational fraction approximation

I need to convert some high precision numbers to rational numbers. There is a function available in MATLAB called rat which does this for double precision numbers. For example if there are a couple of numbers different beyond the double precision decimal digits, then rat gives the same result. I tried to fix this by reducing the tolerance but it did not help. Is there any solutions available for this?
If I could have access to the source code of rat it would be possible to update it for high precision numbers as well.

Best Answer

I decided to get this working. Easy enough. And since I had to post a bug fix for something in HPF anyway, I pushed it to the top of my list.
So in the most recently uploaded version of HPF, there is now a rat function, using a continued fraction approximation to any HPF floating point number. It uses a few divides, so while I'd like it to be faster, it works nicely for numbers on the order of a few hundred digits in precision.
[N,D] = rat(hpf('pi',100),hpf('1e-101'))
N =
394372834342725903069943709807632345074473102456264
D =
125532772013612015195543173729505082616186012726141
N/D
ans =
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
hpf('pi',100)
ans =
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068