'Casts a value to the data type of the instance.
Parameters
value : number
rtol : floating point number
Relative tolerance. (will be deduced if not given).
atol : floating point number
Absolute tolerance (in addition to ``rtol``).
limits : dict
Values given by ``limits.h``, x86/IEEE754 defaults if not given.
Default: :attr:`default_limits`.
type_aliases : dict
Maps substitutions for Type, e.g. {integer: int64, real: float32}
Examples
>>> from sympy.codegen.ast import Type, integer, float32, int8
>>> integer.cast_check(3.0) == 3
True
>>> float32.cast_check(1e-40)  # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: Minimum value for data type bigger than new value.
>>> int8.cast_check(256)  # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: Maximum value for data type smaller than new value.
>>> v10 = 12345.67894
>>> float32.cast_check(v10)  # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: Casting gives a significantly different value.
>>> from sympy.codegen.ast import float64
>>> float64.cast_check(v10)
12345.67894
>>> from sympy import Float
>>> v18 = Float(\'0.123456789012345646\')
>>> float64.cast_check(v18)
Traceback (most recent call last):
ValueError: Casting gives a significantly different value.
>>> from sympy.codegen.ast import float80
>>> float80.cast_check(v18)
0.123456789012345649'

def cast_check(self, value, rtol=None, atol=0, limits=None, precision_targets=None):

    from sympy.functions.elementary.complexes import im, re
    val = sympify(value)
    ten = Integer(10)
    exp10 = getattr(self, 'decimal_dig', None)
    if (rtol is None):
        rtol = (1e-15 if (exp10 is None) else (2.0 * (ten ** (- exp10))))
    def tol(num):
        return (atol + (rtol * abs(num)))
    new_val = self._cast_nocheck(value)
    self._check(new_val)
    delta = (new_val - val)
    if (abs(delta) > tol(val)):
        raise ValueError('Casting    gives    a    significantly    different    value.')
    return new_val
