C++ rewrite of rpoly.f