fixed build problem with isnan on mac os x

compiler couldn't find the isnan function in the math library because is in another namespace. It suggested to use std::isnan but this wouldn't work for the case where we define isnan locally.