Search code examples
.netbit-shift

Specifics about shifting floating point data types in .Net?


If I remember right, a double or float is broken into 3 parts: a sign bit, the exponent, and the mantissa.

When a double is shifted, do the bits shift the entire binary of the variable or does it just shift the mantissa?


Solution

  • You can't shift floating point types - in C# at least.

    On the other hand, if you were to multiply or divide by two repeatedly, you'd see what I mentioned before: within the range of normalized numbers, shifting left would increase the exponent by one and shifting right would decrease the exponent by one. Within denormal numbers, the exponent is fixed at 0, so the mantissa has to change.

    EDIT: To answer your comment, a value represents a subnormal/denormal number if the exponent is zero and the mantissa is non-zero. See this page for more information on IEEE 754 in general, and I have a page on .NET binary floating point.