Is there a fast function "ExactExpressionQ
" to test whether an expression is exact vs inexact? I'm looking for something like ExactNumberQ
that works for expressions.
My attempt at this is
ExactExpressionQ[expr_] := FreeQ[expr, _Real|_Complex?InexactNumberQ]
ExactExpressionQ[0]
ExactExpressionQ[0.]
ExactExpressionQ[(2.1 + I) x]
ExactExpressionQ[Sin[x]]
(* True *)
(* False *)
(* False *)
(* True *)
Is there something better?
Floor[1.4*x]
is treated as inexact? I thinkFloor
always produces exact integers if given numbers, whether exact or inexact. $\endgroup$ExactExpressionQ
tests whether the input expression is literally exact or not. $\endgroup$Complex
can head an exact number. Have to peek inside... $\endgroup$ExactExpressionQ[expr_] := FreeQ[expr, _?InexactNumberQ]
$\endgroup$-1
would help and still give the desired result. (Can't test here though). $\endgroup$