C++ – A few things about division by zero in C

cvisual c++

Possible Duplicate:
Value returning 1.#INF000

I always thought division by 0 would result in a compiled program crashing

However I discovered today (using VC++ 2010 Express) that division by 0 gives something called 1.#INF000 and it is supposed to be positive infinity

When it was passed to a function, it got passed as -1.#IND000

What is this all about?

Searching 1.#INF000 and -1.#IND000 on google do not provide any clear explanations either

Is it just something specific to VC++ ?

Best Answer

Floating point division by zero behaves differently than integer division by zero.

The IEEE floating point standard differentiates between +inf and -inf, while integers cannot store infinity. Integer division by zero results in undefined behaviour. Floating point division by zero is defined by the floating point standard and results in +inf or -inf.

Edit:

As pointed out by Luchian, C++ implementations are not required to follow the IEEE Floating point standard. If the implementation you use doesn't follow the IEEE Floating point standard the result of floating point division by zero is undefined.