J
John Harrison
I have a problem. I want to compare an integral value, n, against three
half open ranges as follows
[-A, 0) // range 1
[0, B) // range 2
[B, C} // range 3
Each range corresponds to a different outcome and if the integral value
isn't within any of the ranges, that's a fourth outcome. So far so easy,
the problem is that n is a signed quantity and A, B, C are unsigned
quantities. Apart from this obscure corner of my code this makes perfect
sense, so I don't want to change the signedness of anything.
How to I write these tests so that my code is reasonably understandable,
rather than a horrible mess of casts and compiler warnings?
One more point, of the unsigned quantity, only B is guaranteed small
enough that it could be safely cast to a signed integer.
john
half open ranges as follows
[-A, 0) // range 1
[0, B) // range 2
[B, C} // range 3
Each range corresponds to a different outcome and if the integral value
isn't within any of the ranges, that's a fourth outcome. So far so easy,
the problem is that n is a signed quantity and A, B, C are unsigned
quantities. Apart from this obscure corner of my code this makes perfect
sense, so I don't want to change the signedness of anything.
How to I write these tests so that my code is reasonably understandable,
rather than a horrible mess of casts and compiler warnings?
One more point, of the unsigned quantity, only B is guaranteed small
enough that it could be safely cast to a signed integer.
john