Re: NumberForm question
- To: mathgroup at smc.vnet.net
- Subject: [mg82049] Re: NumberForm question
- From: DrMajorBob <drmajorbob at bigfoot.com>
- Date: Wed, 10 Oct 2007 04:31:11 -0400 (EDT)
- References: <20828645.1191825480672.JavaMail.root@m35> <fefihj$jm0$1@smc.vnet.net> <13608238.1191965108403.JavaMail.root@m35>
- Reply-to: drmajorbob at bigfoot.com
I didn't follow all that, but here's an annoying "feature": x=1+3*$MachineEpsilon; NumberForm[x,{16,16}] InputForm[x] 1.0000000000000010 1.0000000000000007 InputForm[x] NumberForm[x,{16,16}] 1.0000000000000010 1.0000000000000007 InputForm[x] 1.0000000000000007 So InputForm displays out of order, compared to the inputs within a cell. Bobby On Tue, 09 Oct 2007 09:59:06 -0500, Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com> wrote: > DrMajorBob wrote: > >> I thought I had an answer: the 2 in your InputForm output is in the >> 17th decimal position (counting from the leading decimal as 1st >> position), so 16-digit precision leaves it out in the NumberForm output. >> $MachineEpsilon >> 2.22045*10^-16 >> BUT: >> NumberForm[x,{100,100}] >> = >> 1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 >> From that, I'd think x is simply 1.0 (contradicting the InputForm). >> But no, since: >> RealDigits[x, 2] >> {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, >> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, >> 0, 0, 0, 0, 0, 0, 0, 1}, 1} >> So... you got me, I have no idea why! > <snip> > > If this was not weird enough, we can see that we add three > $MachineEpsilon to one, then the latest decimal digit are not displayed > or rounded in a consistent way. For instance, compare > 1.0000000000000010 returned by NumberForm versus > 1.0000000000000007 returned by InputForm. > > It looks like if the Interpretation box used with NumberForm is messing > up the displayed number (see below). > > In[1]:= x = 1 + 3*$MachineEpsilon; > NumberForm[x, {16, 16}] > InputForm[x] > > Out[2]//NumberForm= \!\(\* > TagBox[ > InterpretationBox["\<\"1.0000000000000010\"\>", > 1.0000000000000007`, > AutoDelete->True], > NumberForm[#, {16, 16}]& ]\) > > Out[3]//InputForm= > 1.0000000000000007 > > In[4]:= Table[{NumberForm[1 + n*$MachineEpsilon, {16, 16}], > N[FromDigits[RealDigits[1 + n*$MachineEpsilon, 2], 2], 20]}, {n, 5}] > > Out[4]= {{\!\(\* > TagBox[ > InterpretationBox["\<\"1.0000000000000000\"\>", > 1.0000000000000002`, > AutoDelete->True], > NumberForm[#, {16, 16}]& ]\), 1.0000000000000002220}, {\!\(\* > TagBox[ > InterpretationBox["\<\"1.0000000000000000\"\>", > 1.0000000000000004`, > AutoDelete->True], > NumberForm[#, {16, 16}]& ]\), 1.0000000000000004441}, {\!\(\* > TagBox[ > InterpretationBox["\<\"1.0000000000000010\"\>", > 1.0000000000000007`, > AutoDelete->True], > NumberForm[#, {16, 16}]& ]\), 1.0000000000000006661}, {\!\(\* > TagBox[ > InterpretationBox["\<\"1.0000000000000010\"\>", > 1.0000000000000009`, > AutoDelete->True], > NumberForm[#, {16, 16}]& ]\), 1.0000000000000008882}, {\!\(\* > TagBox[ > InterpretationBox["\<\"1.0000000000000010\"\>", > 1.000000000000001, > AutoDelete->True], > NumberForm[#, {16, 16}]& ]\), 1.0000000000000011102}} > > Regards, -- = DrMajorBob at bigfoot.com