This prevents an integer overflow during the difficulty retarget calculation, and fixes a consensus-changing bug introduced by df9eb5e14fa8072bc8a82b59e712c2ba36f13f4c. While it is not possible to hit this consensus bug on mainnet or testnet3 due to the higher current difficulties, it is easily hit on regtest after generating 2016 blocks, forcing the retarget.
Note: to convert between the arith_uint256 and arith_uint512 classes, I created a new static function in the base_uint base class that copies the data from one to the other. However, to do this, I had to make the protected members WIDTH and pn public, so they could be accessed. Not too happy with this, and I think that I need to use friend to allow access, but I'm not sure exactly how to do that. Suggestions welcome.