MathGroup Archive 2008

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

Search the Archive

Re: IsIntegerOrFloat

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87047] Re: IsIntegerOrFloat
  • From: Albert Retey <awnl at arcor.net>
  • Date: Sun, 30 Mar 2008 01:16:03 -0500 (EST)
  • References: <fsl214$g77$1@smc.vnet.net>

Hi,

> I need a function
> 
>                  IsIntegerOrFloat[expr]
> 
> that returns True if expr, which is generally a flat list, contains
> only integers or floating point numbers, and False otherwise.
> Rational numbers such as 1/2 are considered symbolic for this test; so is
> \[Pi] or Sqrt[5]. Appearance of any symbol, as in 2.0*a+3.5, makes it False.
> As in previous questions, this should work on versions >=4.0.
> 
Is this what you need?

In[45]:= ClearAll[IsIntegerOrFloat]
In[47]:= IsIntegerOrFloat[n_Real]:=True
In[48]:= IsIntegerOrFloat[n_Integer]:=True
In[54]:= IsIntegerOrFloat[lst_List]:=And@@(IsIntegerOrFloat/@lst)
In[55]:= IsIntegerOrFloat[___]:=False
In[56]:= IsIntegerOrFloat[1]
Out[56]= True
In[57]:= IsIntegerOrFloat[1/3]
Out[57]= False
In[58]:= IsIntegerOrFloat[1.4]
Out[58]= True
In[59]:= IsIntegerOrFloat[\[Pi]]
Out[59]= False
In[60]:= IsIntegerOrFloat[2.0*a+3.5]
Out[60]= False
In[61]:= IsIntegerOrFloat[{1,2,3,0.8,6.9}]
Out[61]= True
In[62]:= IsIntegerOrFloat[{1,2,3,0.8,6.9,1/2}]
Out[62]= False
In[63]:= IsIntegerOrFloat[{1,2,3,0.8,6.9,a}]
Out[63]= False

I think this would even work with version 1 or 2 :-)

hth,

albert


  • Prev by Date: Global setting of Graphics options for plot, listplot, listlogplot...
  • Next by Date: Re: Number of monomials
  • Previous by thread: Re: IsIntegerOrFloat
  • Next by thread: Re: IsIntegerOrFloat