Factor out common logic into some reasonable commented helper functions. In the process, ensure that the in-block vs cross-block cases are handled the same. They previously weren't.
(Carefully review here would be appreciated. I'm by no means a floating point expert and am going solely off existing comments and LangRef.)