Refactored hp_from_double()