- To: mathgroup at smc.vnet.net
- Subject: [mg87049] Re: IsIntegerOrFloat
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Sun, 30 Mar 2008 01:16:26 -0500 (EST)
- Organization: University of Bergen
- References: <firstname.lastname@example.org>
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. 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 ...