Malcolm said:
No, but it's "safe enough". If you do need the speed increment, it is
probably worth the small risk that someone will run your code on a system
that doesn't use all bits zero for float 0.0.
I don't *quite* agree that it's "safe enough".
If I were going to use memset() to zero an array of floats, the first
thing I'd do is measure the performance to see if memset() really is
faster. If it isn't, there's no point in using anything other than an
explicit loop, which is known to be safe.
If I found that memset() really is faster, *and* that the increase in
performance is actually significant, I'd probably write a test
function, to be invoked once at program startup, that checks whether
0.0 really is all-bits-zero. If it isn't, it would abort the program.
If the program is eventually ported to a system were 0.0 *isn't*
all-bits-zero, it will then abort immediately rather than running
and giving mysteriously incorrect results.
If even invoking the test function once is a problem, I'd move the
test into the build procedure, so the program won't even build unless
it's first proven that 0.0 is all-bits-zero.
For that matter, as long as I'm messing with the build procedure, I
might as well have it set a macro that indicates whether memset() is
safe, and use that in the code to determine at compilation time which
method to use.
The only problem with this is that it's difficult to find a platform
on which 0.0 *isn't* all-bits-zero, so any code that assumes it isn't
may not be tested properly.