MathGroup Archive 2008

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

Search the Archive

Re: IsIntegerOrFloat

  • To: mathgroup at
  • Subject: [mg87049] Re: IsIntegerOrFloat
  • From: Szabolcs Horvát <szhorvat at>
  • Date: Sun, 30 Mar 2008 01:16:26 -0500 (EST)
  • Organization: University of Bergen
  • References: <fsl214$g77$>

carlos at 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.

iiof[expr_] := VectorQ[expr, Head[#] === Integer || Head[#] === Real &]

> 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.

Conversion to strings is generally not necessary for simple formatting ...

  • Prev by Date: Re: Re: Mathematica notebooks the best method
  • Next by Date: Re: symbolic evaluation
  • Previous by thread: Re: IsIntegerOrFloat
  • Next by thread: Re: IsIntegerOrFloat