fixed almostEqual function, lifted from en.cppreference.com