MathGroup Archive 1998

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

Search the Archive

Re: Very odd behaviour in Mod/N



Adrian Cable wrote:
> 
> Hi there,
> I've observed some very odd behaviour when using Mod and N. It seems
> that, when handling very large numbers, Mathematica (3.0.1, Win32) does
> not display machine-precision results correctly. Here's an example
> which behaves as it should:
> 
> In[12]:= Q = 10^8
> Out[12]= 100000000
> 
> In[13]:= t = Mod[Q, 2 Pi]
> Out[13]= 100000000 - 31830988 Pi
> 
> In[14]:= N[t]
> Out[14]= 1.9427
> 
> In[15]:= N[t, 20]
> Out[15]= 1.9426951345040144600
> 
> Now for a very similar example which obviously behaves wrongly:
> 
> In[16]:= Q = 10^18
> Out[16]= 1000000000000000000
> 
> In[17]:= t = Mod[Q, 2 Pi]
> Out[17]= 1000000000000000000 - 318309886183790670 Pi
> 
> In[18]:= N[t]
> Out[18]= 128.
> 
> In[19]:= N[t, 20]
> Out[19]= 4.831039164951128133
> 
> What exactly is going on here?
> 
> Thanks, cheers,
> Adrian Cable.


With In[18] you are working with machine arithmetic. On most platforms
this has about 16 digits of precision (and no control for round-off or
cancellation error). You require 18 digits precision at least in order
to get this computed correctly. So it is not surprising that you got
errors in the 16th place, which becomes the most significant digit due
to large-scale cancellation.

Daniel Lichtblau
Wolfram Research



  • Prev by Date: RE: Very odd behaviour in Mod/N
  • Next by Date: Re: Sqrt Problems
  • Prev by thread: Very odd behaviour in Mod/N
  • Next by thread: RE: Very odd behaviour in Mod/N