changed type of tmp var from double to unsigned