Copied from Boost.Geometry, including original tests, with some non-functional modifications explained in the comments. The utility can be used where it is important to avoid integer overflow.