Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: NumberForm question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82026] Re: NumberForm question
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Wed, 10 Oct 2007 04:19:20 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <20828645.1191825480672.JavaMail.root@m35> <fefihj$jm0$1@smc.vnet.net>

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,
-- 
Jean-Marc


  • Prev by Date: Re: NumberForm question
  • Next by Date: Re: rule based program for "Deleting repeated members of a list."
  • Previous by thread: Re: NumberForm question
  • Next by thread: Re: NumberForm question