tags:

views:

32

answers:

2

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?

+2  A: 

EDIT: Doh - ignore previous version of answer.

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

On the other hand, if you were to multiple 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.

Jon Skeet
Do you have a link for the difference between normalized and denormal floating points? Given a double that's been pulled out of a database or a file, how can you tell if it's normalized or not?
Corey Ogburn
Given that your previous answer may not have applied in .Net... You still peeked my interested about normalized and denormalized numbers, where can I read up on those even if they're not .Net specific?
Corey Ogburn
@Corey: I've expanded my contracted answer, including a couple of links.
Jon Skeet
Picked for answer (and +1) because of extra information including how I would just shift the exponent.
Corey Ogburn
+1  A: 

As far as I know, shift operators are only defined on Integers in .Net.

Peladao