It depends if you use the sine function (opposite over hypotenuse. elevation gain over actual distance traveled) or if you use the Tangent function (opposite over adjacent. elevation gain over horizontal distance.)
In real world cases they come out very close to each other but in extreme cases they begin to differ a lot.