By design, why does the C# compiler allows any float or double values to be divided by zero?
class Program
{
static void Main(string[] args)
{
double x = 0.0 / 0;
float y = 1f / 0;
}
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because IEEE 754 floating-point values have special non-numeric values to deal with this:
whereas dividing an integer by zero is always an exception (in the C# sense1), so you could just throw the exception directly.
1 Dividing a floating-point number by zero is also an exception but at a completely different level and many programming languages abstract this away.