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

Interview Question

Software Engineer Interview

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

  same polarity?
Answer

Interview Answer

3 Answers

3

Multiply them together and compare greater than zero.

Interview Candidate on Nov. 4, 2014
3

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 May 19, 2016
2

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 Aug. 7, 2016

Add Answers or Comments

To comment on this, Sign In or Sign Up.