Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: When Is Precision[ ] $MachinePrecision, And When Is It Not?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47467] Re: When Is Precision[ ] $MachinePrecision, And When Is It Not?
  • From: drbob at bigfoot.com (Bobby R. Treat)
  • Date: Tue, 13 Apr 2004 06:26:19 -0400 (EDT)
  • References: <c5dhrd$nqp$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Machine precision (on my machine, at least) is 53 bits:

Log[2, 10^$MachinePrecision]
53.

The default display for machine precision numbers is just 6 digits;
that's why NumberForm (or other intervention) is needed to see more.
Notice that NumberForm counts base ten digits, even when its argument
is in base 2.

x = 2./3.; 
(NumberForm[BaseForm[x, 2], 
    #1] & ) /@ Range[14, 18]

(output suppressed)

Here we can see the actual binary digits and a mantissa:

RealDigits[2./3.,2]
Length@First@%

{{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
    0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},0}
53

Help says, "NumberForm acts as a ?wrapper?, which affects printing,
but not evaluation." That is, NumberForm[x,n] is equal to the original
x; it merely prints or displays differently, and that's why Precision
doesn't change with the number of displayed digits.

But evaluation actually IS affected:

NumberForm[BaseForm[x,2],16];
%==2
3/2 NumberForm[BaseForm[x, 2], 16]

False
(output suppressed, but not 1.0 as it should be)

Other so-called "wrappers" in Mathematica (such as MatrixForm) also
fail (miserably) to live up to documentation. But oh well; that's
life!!

Bobby

Harold.Noffke at wpafb.af.mil (Harold Noffke) wrote in message news:<c5dhrd$nqp$1 at smc.vnet.net>...
> $Version "5.0 for Microsoft Windows [2000] (November 18, 2003)"
> 
> MathGroup:
> 
> Some follow-up to Peng Yu's 2004-04-09 post on numerical precision.
> 
> On my machine, I get ...
> 
> 	In[1]:= $MachinePrecision
> 	Out[1]= 15.9546
> 
> 	In[2]:= NumberForm[2./3.]
> 	Out[2]//NumberForm= 0.666667
> 
> 	In[3]:= NumberForm[2./3., $MachinePrecision]
> 	NumberForm::iprf:
> 	   Formatting specification 15.9546
> 	     should be a positive integer or a pair of positive integers.
> 	Out[3]//NumberForm= 0.666667
> 
> So, it seems obvious I can't display numbers to $MachinePrecision
> exactly, because $MachinePrecion is not an integer.  However ...
> 
> 	In[2]:= NumberForm[2./3., 15]
> 	Out[2]//NumberForm= 0.666666666666667
> 
> 	In[3]:= NumberForm[2./3., 15] // Precision
> 	Out[3]= MachinePrecision
> 
> 	In[4]:= NumberForm[2./3., 16]
> 	Out[4]//NumberForm= 0.6666666666666666
> 
> 	In[5]:= NumberForm[2./3., 16] // Precision
> 	Out[5]= MachinePrecision
> 	
> 	In[6]:= NumberForm[2./3., 20] // Precision
> 	Out[6]= MachinePrecision
> 	
> At this point, it looks like 15-digit numbers get rounded, as I
> expect.  However, 16- and larger-digit numbers do not get rounded, and
> Mathematica continues to print "MachinePrecision" instead of
> "Arbitrary-Precision".  What I expect here is for rounding to
> continue, and for Mathematica to print "Arbitrary-Precision" instead
> of "MachinePrecision" when the number of digits specified become 16 or
> greater.
> 
> Clearly I am missing one of Mathematica's syntax subtilties.  Can
> someone please clarify this?
> 
> Thanks.
> Harold


  • Prev by Date: Re: Re: Adding hyperlinks to help browser files in function::usage
  • Next by Date: DirectMath experience
  • Previous by thread: When Is Precision[ ] $MachinePrecision, And When Is It Not?
  • Next by thread: Re: When Is Precision[ ] $MachinePrecision, And When Is It Not?