Re: Union[{Pi, N[Pi]}]
- To: mathgroup at smc.vnet.net
- Subject: [mg12760] Re: [mg12739] Union[{Pi, N[Pi]}]
- From: Carl Woll <carlw at fermi.phys.washington.edu>
- Date: Wed, 10 Jun 1998 03:04:20 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Hi Mark, The problem, I think, is that N always returns a machine precision number when the precision is less than 16. Try the following: v1 = 3.14159; v2 = N[v1,3]; v1 === v2 InputForm[v2] MachineNumberQ[v2] and you will see that v1 and v2 are the same, and v2 is still a machine precision number. So, if you want to work with arbitrary precision numbers with precision less than 16, don't use the function N. An alternative may be to use the function SetPrecision. For example, Union[{3.14159,Pi},SameTest->SetPrecision[#1,3]===SetPrecision[#2,3]] Union[SetPrecision[{3.14159,Pi},3],SameTest->SameQ] return {3.14159} {3.14} although Union[SetPrecision[{3.14159,Pi},3]] returns {3.14,3.14} If you share some more details of your problem, someone may be able to offer a better approach. Carl Woll Dept of Physics U of Washington On Fri, 5 Jun 1998, Mark C McClure wrote: > We've seen the Union[{0,0.}] disscussion. Here's a little variation > which seems a little trickier. > > In[8]:= > N[{3.141592, Pi}, 3] // Union > > Out[8]= > {3.14,3.14} > > > In[11]:= > Union[N[{3.141592, Pi},3] , > SameTest -> (N[#1,3] == N[#2,3]&)] > > Out[11]= > {3.14,3.14} > > > In[14]:= > Union[{Pi, N[Pi]} // N] > > Out[14]= > {3.14159} > > > The last one works works, but the first one represents my situation more > accurately. > > -- > Mark McClure > Department of Mathematics > University of North Carolina at Asheville http://www.unca.edu/~mcmcclur/ > mcmcclur at bulldog.unca.edu >