Made use of <cmath> and std::isfinite to pander to gnu++0x mode in g++-4.6.3.