#1,093 – How Positive and Negative Zero Values Are Stored

.NET can represent both positive and negative zero floating point values.  They are stored as 32-bit floating point values as follows:

  • +0 : sign bit 0, mantissa 0 (23 bits), exponent 0 (8 bits)
  • -0: sign bit 1, mantissa 0 (23 bits), exponent 0 (8 bits)

A 32-bit positive zero is therefore stored as 00000000 (hex) and negative zero as 80000000 (hex).  We can verify this by looking at these values in memory from within Visual Studio.

Assuming the following code:

            float zero = 0.0f;
            float negZero = -0.0f;

Positive zero:

1093-001

Negative zero:

1093-002

 

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

One Response to #1,093 – How Positive and Negative Zero Values Are Stored

  1. Pingback: Dew Drop – May 9, 2014 (#1773) | Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: