Works for both -ve and +ve inputs within range