I made some changes to the original function (which was based off older portalr code). The new portalr code has extended functionality that makes for a simpler version. Checking for equivalence would be good, and correcting the rounding (since R rounds to even by default).