5 ms·
1/0 is not equal to 2/0, they are both errors but not the same.
by voidr 15y ago
1/0 is not equal to 2/0, they are both errors but not the same.
- deleted 15y ago[deleted]
- cdavid 15y agoactually, they are both equal to infinity: #include <stdio.h> int main() { float a = 1. / 0; float b = 2. / 0; printf("%f == %f ? %d\n", a, b, a == b); return 0; } will print: inf == inf ? 1 Moreover: #include <stdio.h> int main() { float a = 0. / 0; float b = a; printf("%f == %f ? %d\n", a, b, a == b); return 0; } nan == nan ? 0 So this is certainly surprising without knowing quite a bit already about floats, because it means = is not only not transitive but even not reflexive.
- blinks 15y agoActually, they're _not_ both equal to infinity, in the mathematical sense (which I believe you're discussing) -- X / 0 is undefined. What's equal to infinity is the limit of 1 / x as x approaches 0, and that's only from the positive side. From the negative side, it's -infinity.
- cdavid 15y agoNobody is discussing about usual mathematical definitions: this is about the IEEE754 standard. In that context, x / 0 is defined (to positive infinity). I was pointing the error of the OP about the explanation about Nan != Nan.
- ajross 15y agoActually no. Just in case you were confused by cdavid's sample code: the concise explanation is that division by zero in IEEE floating point produces an infinity (there are two: positive and negative), not a NaN. Neither is necessarily an "error" in the sense of a runtime exception (the generation of which is programmable).