Change operands of subtraction expression to have well-defined behaviour.
authorA. Unique TensorFlower <gardener@tensorflow.org>
Wed, 18 Apr 2018 18:46:07 +0000 (11:46 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Wed, 18 Apr 2018 18:48:46 +0000 (11:48 -0700)
commit31f925c7783fb8fa58278b31585dcf7bdb4cfd8c
tree36447c2455927321989e6cdbc65b8268187b2c3b
parentce7a92a62a6bbf0765e68a3340fe3efb07ac1e2b
Change operands of subtraction expression to have well-defined behaviour.

At present, signed arithmetic overflows (i.e. has undefined behaviour) in general, e.g. when computing 0 - INT_MIN or INT_MAX - INT_MIN. The fact that we want the result in the unsigned type does not help us here.

The fix is to convert the operands to the corresponding unsigned type first and then perform the operation in unsigned arithmetic, which is well-defined and has the correct subtraction behaviour.

PiperOrigin-RevId: 193391813
tensorflow/core/lib/random/random_distributions.h