def as_int(n):
try:<EOL><INDENT>result = int(n)<EOL>if result != n:<EOL><INDENT>raise TypeError<EOL><DEDENT><DEDENT>except TypeError:<EOL><INDENT>raise ValueError('<STR_LIT>' % n)<EOL><DEDENT>return result<EOL>
Convert the argument to a builtin integer.

The return value is guaranteed to be equal to the input. ValueError is
raised if the input has a non-integral value.

Examples
========

>>> from sympy.core.compatibility import as_int
>>> from sympy import sqrt
>>> 3.0
3.0
>>> as_int(3.0) # convert to int and test for equality
3
>>> int(sqrt(10))
3
>>> as_int(sqrt(10))
Traceback (most recent call last):
...
ValueError: ... is not an integer