boost::rational

tested how it works.