@tf_export('dtypes.saturate_cast', 'saturate_cast')
@dispatch.add_dispatch_support
def saturate_cast(value, dtype, name=None):
    'Performs a safe saturating cast of `value` to `dtype`.\n\n  This function casts the input to `dtype` without applying any scaling.  If\n  there is a danger that values would over or underflow in the cast, this op\n  applies the appropriate clamping before the cast.\n\n  Args:\n    value: A `Tensor`.\n    dtype: The desired output `DType`.\n    name: A name for the operation (optional).\n\n  Returns:\n    `value` safely cast to `dtype`.\n  '
    with ops.name_scope(name, 'saturate_cast', [value]) as name:
        value = ops.convert_to_tensor(value, name='value')
        dtype = dtypes.as_dtype(dtype).base_dtype
        if (value.dtype.min < dtype.min):
            value = gen_math_ops.maximum(value, ops.convert_to_tensor(dtype.min, dtype=value.dtype, name='min'))
        if (value.dtype.max > dtype.max):
            value = gen_math_ops.minimum(value, ops.convert_to_tensor(dtype.max, dtype=value.dtype, name='max'))
        return cast(value, dtype, name=name)
Performs a safe saturating cast of `value` to `dtype`.

This function casts the input to `dtype` without applying any scaling.  If
there is a danger that values would over or underflow in the cast, this op
applies the appropriate clamping before the cast.

Args:
  value: A `Tensor`.
  dtype: The desired output `DType`.
  name: A name for the operation (optional).

Returns:
  `value` safely cast to `dtype`.
@tf_export('dtypes.saturate_cast', 'saturate_cast')
@dispatch.add_dispatch_support
def saturate_cast(value, dtype, name=None):
    'Performs a safe saturating cast of `value` to `dtype`.\n\n  This function casts the input to `dtype` without applying any scaling.  If\n  there is a danger that values would over or underflow in the cast, this op\n  applies the appropriate clamping before the cast.\n\n  Args:\n    value: A `Tensor`.\n    dtype: The desired output `DType`.\n    name: A name for the operation (optional).\n\n  Returns:\n    `value` safely cast to `dtype`.\n  '
    with ops.name_scope(name, 'saturate_cast', [value]) as name:
        value = ops.convert_to_tensor(value, name='value')
        dtype = dtypes.as_dtype(dtype).base_dtype
        if (value.dtype.min < dtype.min):
            value = gen_math_ops.maximum(value, ops.convert_to_tensor(dtype.min, dtype=value.dtype, name='min'))
        if (value.dtype.max > dtype.max):
            value = gen_math_ops.minimum(value, ops.convert_to_tensor(dtype.max, dtype=value.dtype, name='max'))
        return cast(value, dtype, name=name)