mercredi 4 octobre 2023

How to map a signed integer in range A..B into a subrange C..D?

I have a signed random integer in range A..B. What is the formula to map from A..B into a subrange C..D where C >= A and D <= B?

For unsigned integers, I can use A + (num % (B - A)). What's the equivalent of this for signed?




Aucun commentaire:

Enregistrer un commentaire