tf.cast behaves differently in CPU and GPU when casting negative values
The result of casting a negative float to an int is undefined according to the C++ standard:
> A prvalue of a floating-point type can be converted to a prvalue of an
integer type. The conversion truncates; that is, the fractional part is
discarded.
> The behavior is undefined if the truncated value cannot be represented
in the destination type.

https://github.com/cplusplus/draft/blob/5ef31f3fc1531d9e6e923cb57bf6e5ecec59ed4e/source/expressions.tex#L949-L958

It's mentioned in more readable language here (unofficial):
* https://cplusplus.com/doc/tutorial/typecasting/
* https://embeddeduse.com/2013/08/25/casting-a-negative-float-to-an-unsigned-int/

Perhaps TF could either print a warning message or work around it by either:
* taking absolute value of the floating-point value first, or
* casting to a signed int type first @tilakrayal 
 
I was able to reproduce the issue on Colab using TF v2.11 and tf-nightly. Please find the gist of [2.11](https://colab.research.google.com/gist/tiruk007/fb8c930fed1e0f533966180067793815/2_11.ipynb) and [tf-nightly](https://colab.research.google.com/gist/tiruk007/538982863653d5f46152ee2f853ef874/untitled134.ipynb) for reference.

Thank you ! Hi, @trickiwoo 

Apologize for the delay and @nrwahl2, Thank you for the detailed explanation and suggested workaround, I really appreciate your efforts and time, I was able to replicate the same issue with `tensorflow 2.12.0rc0` and I have added [gist-file](https://colab.research.google.com/gist/gaikwadrahul8/6f28a09e97fd4597c26ad01d4a7cc54a/-59702.ipynb) for your reference. 

It is undefined behaviour in `C99` if the floating point number is` less than or equal to -1.0`. If it's in the range `(-1.0, 0.0),` the resulting value will be 0.

**From C99, §6.3.1.4, paragraph 1**

`When a finite value of real floating type is converted to an integer type other than _Bool, the fractional part is discarded (i.e., the value is truncated toward zero). If the value of the integral part cannot be represented by the integer type, the behavior is undefined`

We'll have to dig more into this issue and we'll update you soon. Thank you!  This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.
 Hi, @sachinprasadhs 

Could you please look into this issue ? Thank you!
<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

Yes

### Source

source

### Tensorflow Version

2.13.0.dev20230204

### Custom Code

Yes

### OS Platform and Distribution

Ubuntu 20.04.4 LTS

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

```shell
tf.cast behaves differently in CPU and GPU when casting negative values
```


### Standalone code to reproduce the issue

```shell
import tensorflow as tf
import numpy as np

with tf.device('cpu'):
    data = np.array([[-1.0]]).astype(np.float64)
    x = tf.dtypes.cast(data, tf.uint8)
    print(x)
    
with tf.device('gpu'):
    data = np.array([[-1.0]]).astype(np.float64)
    x = tf.dtypes.cast(data, tf.uint8)
    print(x)
```


### Relevant log output

```shell
tf.Tensor([[255]], shape=(1, 1), dtype=uint8)
tf.Tensor([[0]], shape=(1, 1), dtype=uint8)
```
</details>