Piecewise fix for 0d

I provide a fix for #331. Actually little changes were needed, but I had to carefully think about the assumptions being made by the function. Some additional tests were added and the behavior remains backwards compatible.

Besides, I corrected the documentation because there was an inconsistent bit, see 0d1f7d3.
in principle the documentation defines the interface but if our tets rely on it maybe also third party software

using 0 has the advantages that it is defined for all types (including integers) and the memory can be sparsely allocated on capable operating systems, so I guess it is fine to keep it.
thanks, merging