4 ms·
@Mystical answers in the comment section: Now that I look at the assembly, not even + 0.0f gets optimized out. If I had to guess, it could be that + 0.0f would
by chrisaycock 15y ago
@Mystical answers in the comment section:
Now that I look at the assembly, not even + 0.0f gets optimized out. If I had to guess, it could be that + 0.0f would have side-effects if y[i] happened to be a signalling NaN or something.
- onedognight 15y agoConsider this: x += 0.0; If x = -0.0 (yes, zero has a sign) then adding 0.0 gives 0.0, so it can have an effect and optimizing it away is wrong and generally only allowed with -ffast-math.
- jimmybot 15y agoWhat's an example of 0 having a sign being useful?
- stephencanon 15y agoIf you're seriously interested, read Kahan's "Branch Cuts for Complex Elementary Functions (or: Much Ado About Nothing's Sign Bit)". TLDR: there are some classes of problems for which the sign bit of zero preserves enough important information to get an accurate solution to a problem that would not be possible if you only had an unsigned zero. These happen to turn up in certain types of conformal mappings that are useful for solving certain PDEs.
- lelf 15y ago1/(0-0) = -∞, 1/(0+0) = ∞
- stephencanon 15y agoActually, (0-0) evaluates to +0 in the default rounding mode, so both of those expressions will typically return +∞. 1/-0 will give you -∞, of course.
- lelf 15y agoWell, I meant it as in math notation, not in C. (Strictly speaking, 1/0 in C is kaboom! (undefined behaviour))