Re: Re: MemberQ
- To: mathgroup at smc.vnet.net
- Subject: [mg68612] Re: [mg68561] Re: MemberQ
- From: leigh pascoe <leigh at cephb.fr>
- Date: Sun, 13 Aug 2006 05:52:21 -0400 (EDT)
- References: <0533005404FE2E45B90AF737DE5A991A015312F3@de01exm67.ds.mot.com>
- Sender: owner-wri-mathgroup at wolfram.com
Erickson Paul-CPTP18 wrote: > Only curious if for you > .7//FullForm > doesn't return 0.7000000000000001` > > -----Original Message----- > From: leigh pascoe [mailto:leigh at cephb.fr] To: mathgroup at smc.vnet.net > Subject: [mg68612] [mg68561] Re: MemberQ > > Adriano Pascoletti wrote: > >> Bruce Colletti wrote .. >> >> >>> Re Mathematica 5.2.0.0. >>> >>> Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does >>> MemberQ[Range[0., 1., .1], .7] return False? >>> >>> Thankx. >>> >>> Bruce >>> >>> >>> >> Because the 0.7 in Range[0.0, 1.0, 0.1] is >> >> In[11]:= >> Range[0.0,1.0,0.1][[8]]//FullForm >> Out[11]//FullForm= >> 0.7000000000000001` >> >> and >> >> In[9]:= >> FullForm[0.7] >> Out[9]//FullForm= >> 0.7` >> >> They differ on the 16th decimal place as can be seen evaluating >> 0.7 - Range[0.0, 1.0, 0.1] >> >> >> >> Adriano Pascoletti >> >> >> >> >> > So the curious thing is that it returns True for Ssezi and for me! > > In[8]:=Range[0.,1.,.1][[8]]//FullForm > MemberQ[Range[0.,1.,.1],.7] > > Out[8]//FullForm=0.7000000000000001` > > Out[9]=True > > LP > > > > > In[8]:=.7//FullForm Range[0.,1.,.1][[8]]//FullForm MemberQ[Range[0.,1.,.1],.7] Out[8]//FullForm=0.7` Out[9]//FullForm=0.7000000000000001` Out[10]=True It seems to me that a better behavior would be an error message: "Exact numbers and fixed precision numbers cannot be compared with MemberQ" or perhaps just "False". While we are talking about MemberQ, what about the following behavior? In[15]:=Range[0,1,1/10] MemberQ[Range[0,1,1/10],2/10] Out[15]=\!\({0, 1\/10, 1\/5, 3\/10, 2\/5, 1\/2, 3\/5, 7\/10, 4\/5, 9\/10, 1}\) Out[16]=True Is the above result correct given that 2/10 doesn't appear in the list produced by the range statement?? On the other hand 0.5 can be represented exactly as a binary number, but In[29]:=MemberQ[Range[0,1,1/10],.5] Out[29]=False LP