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

MathGroup Archive 2008

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

Search the Archive

Re: IsIntegerOrFloat

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87063] Re: [mg87011] IsIntegerOrFloat
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sun, 30 Mar 2008 01:19:04 -0500 (EST)
  • References: <200803290921.EAA16390@smc.vnet.net>

One possibility is:

IsIntegerOrFloat[expr_] :=
  VectorQ[expr, NumberQ[#] && (Head[#] =!= Rational) && (Head[#] =!=  
Complex) &]

Then

IsIntegerOrFloat[{2.3, 5}]
True

IsIntegerOrFloat[{2.3, 1/2}]
False

and so on.


Andrzej Kozlowski


On 29 Mar 2008, at 10:21, carlos at colorado.edu wrote:
> Thanks to all who replied to my previous questions. Those functions  
> work
> fine now. Here is another question - I apologize if it has been  
> asked before.
> 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.
>
> Use: unified printing of simulation data structures in table formats.
> Expressions containing only integers or floats are filtered through
> PaddedForm[] and ToString[], others through Symbol[].  The end
> result (a flat table of strings) is filtered through TableForm with
> appropriate options.
>



  • Prev by Date: Re: Re: symbolic evaluation
  • Next by Date: Re: Re: Wrapping text to fit a rectangle
  • Previous by thread: IsIntegerOrFloat
  • Next by thread: Re: IsIntegerOrFloat