nischayn22
nischayn22

Reputation: 447

Check bit or use boolean?

I get a point in the 2-D plane (x,y) as input. Now I have to check which quadrant it is in, do some Reflections about X-axis and Y-axis and check again which quadrant it is in repeatedly for a large number of times.

I have two approaches but not sure which is better

  1. I can store initially the x,y as boolean and then do boolean operations when Reflecting and hence this will be easy. To tell which quadrant the point is in just check the value is true or false.
  2. Or I can do the normal approach with int and then check the first bit to find which quadrant the point is in

Upvotes: 0

Views: 198

Answers (1)

Luchian Grigore
Luchian Grigore

Reputation: 258648

Neither, just compare your coordinates to 0.

If you store them as boolean, besides losing information, you'll probably get some overhead because of the conversion.

If you check the first bit, it will be less readable.

The compiler will optimize these calls on its own, doubt you'll gain anything from a different approach.

Upvotes: 2

Related Questions