By design, why does the C# compiler allows any float or double values to be divided by zero? -


From design, why does the C # compiler allow a float or double value to divide by zero?

  Program of class {static zero main (string [] args) {double x = 0.0 / 0; Float y = 1f / 0; }}  

Because the IEEE 754 floating-point values ​​deal with special non-numeric values With it:

  PS Home: \ & gt; 1.0 / 0 Infinity PS Home: \ & gt; 0.0 / 0 NaN  

While dividing an integer from zero, there is always an exception ( 1 in C #), so you can throw directly the exception directly . There is also an exception to distributing Floating-Point numbers with zero, but at a completely different level and many programming languages ​​remove this sort of essence. Does.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -