| ▲ | kazinator 5 hours ago | ||||||||||||||||||||||
The inline function receives the operands as arguments, and so whatever they are, they get converted to float. Thus the inline code is effectively like this:
Since v is float, the cast representing the return conversion can be omitted:
Now, if a and b are already float, then it's equivalent. Otherwise not; if they are double or int, we get double or int multiplication in the original open code. | |||||||||||||||||||||||
| ▲ | jcranmer 5 hours ago | parent [-] | ||||||||||||||||||||||
> Now, if a and b are already float, then it's equivalent. Not necessarily! Floating-point contraction is allowable essentially within statements but not across them. By assigning the result of a * b into a value, you prohibit contraction from being able to contract with the addition into an FMA. In practice, every compiler has fast-math flags which says stuff it and allows all of these optimizations to occur across statements and even across inline boundaries. (Then there's also the issue of FLT_EVAL_METHOD, another area where what the standard says and what compilers actually do are fairly diametrically opposed.) | |||||||||||||||||||||||
| |||||||||||||||||||||||