Approaching a real number by a rational number?

How can I build a code that for any real number it will find a rational one that approaches it very closely?

What have you tried so far?

Computers can only represent rational numbers, so it would help if you gave more details about your problem.

well basically this is all it says.
"Write a code that will approximate with a given ε>0 any real number by a rational one"

I'm unsure if you are a student of mathematics , or computer science or both ?
It would be interesting to know if you have been 'taught' anything relevant towards the task you have now been assigned ? it might point the way to approach what you have been asked to do.

I expect you are being asked to implement the continued fractions algorithm.
Continued fractions (st-andrews.ac.uk)
sidenote : the linked slide does have a rather glaring typo, when discussing sqrt(2) it should be 99/70 rather than 89/70

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.