diff --git a/pytato/utils.py b/pytato/utils.py index de611f509..55f9a7881 100644 --- a/pytato/utils.py +++ b/pytato/utils.py @@ -226,11 +226,12 @@ def cast_to_result_type( assert result_dtype != np.bool_ expr = TypeCast(result_dtype, expr) - elif isinstance(expr, (complex,)) and not isinstance(expr, np.generic): - # See https://github.com/inducer/pytato/pull/247 and - # https://github.com/inducer/pytato/issues/542 - expr = np.dtype(type(expr)).type(expr) - return expr + elif isinstance(expr, SCALAR_CLASSES): + # See https://github.com/inducer/pytato/issues/542 + # on why pow() + integers is handled separately + if (op != prim.Power and np.issubdtype(type(expr), np.integer) + and not np.issubdtype(result_dtype, np.integer)): + expr = result_dtype.type(expr) return expr