Checks if a given number falls within a specified range, adjusting for order and inclusive of boundaries.