Naughty Dog Interview Question: What's the fastest way to tel... |

Interview Question

Software Engineer Interview

What's the fastest way to tell if 2 signed floats are the

  same polarity?

Interview Answer

3 Answers


Multiply them together and compare greater than zero.

Interview Candidate on 4 Nov 2014

Perform a XOR comparison of the most significant bit of both numbers. If the result is 1, the resulting float will be negative. Otherwise, it is positive.

John Georgantas on 19 May 2016

Although simpler, the multiplication answer is incorrect: the multiplication can overflow, and the comparison with zero will then be incorrect. The XOR answer is the superior one.

Anonymous on 7 Aug 2016

Add Answers or Comments

To comment on this, Sign In or Sign Up.