Dividing by zero

Don’t forget people, dividing by zero does NOT always throw an exception. Sometimes the result is Infinity. It seems to only throw a DivideByZeroException when the zero is an integer or decimal. Here are my test results for C#.

z = 10 / y;

int y = 0; //throws exception
decimal y = 0; //throws exception
decimal y = 0m; //throws exception
double y = 0; //Infinity
double y = 0d; //Infinity
float y = 0; //Infinity
float y = 0F; //Infinity

REFERENCES
http://msdn.microsoft.com/en-us/library/system.dividebyzeroexception.aspx
http://msdn.microsoft.com/en-us/library/aa691373.aspx
http://www.jaggersoft.com/csharp_standard/14.7.2.htm

Advertisements

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