Re: FractionalPart
- To: mathgroup at smc.vnet.net
- Subject: [mg31242] Re: [mg31232] FractionalPart
- From: BobHanlon at aol.com
- Date: Tue, 23 Oct 2001 04:53:20 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 2001/10/20 5:21:59 AM, erfa11 at hotmail.com writes: >I am new in Mathematica(also in english), and I have this question: >I would like to know the behavior of the function FractionalPart. >See here: > >In[1]:= a=Range[9]^2 >Out[1]= {1,4,9,16,25,36,49,64,81} > >In[2]:= x=Exp[.5 Log[a]] >Out[2]= {1,2.,3.,4.,5.,6.,7.,8.,9.} > >In[3]:= FractionalPart[x] >Out[3]= {0,0.,4.444089x10^-16,0.,0.,1.,0.,0.,1.,1.77639x10^-15} > >But it shoud be 0., all of them,no? > You are seeing the results of using machine precision. a = Range[9]^2 {1, 4, 9, 16, 25, 36, 49, 64, 81} Your results are not integers. The display precision merely makes them appear to be. (x =Exp[0.5*Log[a]])//InputForm {1, 2., 3.0000000000000004, 4., 4.999999999999999, 6., 6.999999999999999, 7.999999999999998, 9.000000000000002} FractionalPart[x]//InputForm {0, 0., 4.440892098500626*^-16, 0., 0.9999999999999991, 0., 0.9999999999999991, 0.9999999999999982, 1.7763568394002505*^-15} For exact results, use exact numbers x =Exp[Log[a]/2] {1, 2, 3, 4, 5, 6, 7, 8, 9} FractionalPart[x] {0, 0, 0, 0, 0, 0, 0, 0, 0}