Re: Is there a simple way to transform 1.1 to 11/10?

*To*: mathgroup at smc.vnet.net*Subject*: [mg92998] Re: Is there a simple way to transform 1.1 to 11/10?*From*: Bill Rowe <readnews at sbcglobal.net>*Date*: Wed, 22 Oct 2008 05:39:46 -0400 (EDT)

On 10/21/08 at 6:24 AM, alain at geophysik.uni-muenchen.de (Alain Cochard) wrote: >I searched the newsgroup and thought I had the solution with >Rationalize: > >In[5]:= Rationalize[1.1,0] > >Out[5]= 11/10 >But >In[9]:= Rationalize[1.000000001,0] >Out[9]= 999999917/999999918 >In[10]:= N[%,20] >Out[10]= 1.0000000010000000830 >So any simple way? Here is one way to achieve what you want. In[24]:= f[x_] := Module[{r = Rationalize[x, 0], p}, p = Round@Log[10, Denominator[r]]; Round[r 10^p]/10^p] In[25]:= f[1.000000001] Out[25]= 1000000001/1000000000 I did a few quick tests and this seems to work correctly for other values. But I have not done extensive testing of this function. Undoubtedly, the issue with Rationalize[1.000000001,0] is the nearest machine number to 1000000001/1000000000//N is closer to 999999917/999999918 than 1000000001/1000000000. This issue (closest machine number) likely impacts the function I created above as well in a manner not easily predicted. That is, I suspect for some values the function above will not output what you expect or desire.