Inelastic energy losses in gases and electronic stopping powers in solids