So you think you know what double.Parse does?
-
I thought I knew, but I was wrong.
double x0 = 1 / 0.0;
double x1 = 1 / -0.0;
double x2 = 1 / double.Parse("0.0");
double x3 = 1 / double.Parse("-0.0");Obviously these are all going to be some sort of infinity (yes you can divide by zero[^], and the result is infinity). One might reasonably expect both
x1
andx3
to be Negative Infinity .. however, onlyx1
is Negative Infinity.x3
is Positive Infinity, which is about as wrong as any answer could possibly be. This implies that double.Parse blatantly ignores the sign of zero. -
I thought I knew, but I was wrong.
double x0 = 1 / 0.0;
double x1 = 1 / -0.0;
double x2 = 1 / double.Parse("0.0");
double x3 = 1 / double.Parse("-0.0");Obviously these are all going to be some sort of infinity (yes you can divide by zero[^], and the result is infinity). One might reasonably expect both
x1
andx3
to be Negative Infinity .. however, onlyx1
is Negative Infinity.x3
is Positive Infinity, which is about as wrong as any answer could possibly be. This implies that double.Parse blatantly ignores the sign of zero.harold aptroot wrote:
the sign of zero
Sounds like something Sherlock Holmes (or his smarter brother) would investigate.
-
I thought I knew, but I was wrong.
double x0 = 1 / 0.0;
double x1 = 1 / -0.0;
double x2 = 1 / double.Parse("0.0");
double x3 = 1 / double.Parse("-0.0");Obviously these are all going to be some sort of infinity (yes you can divide by zero[^], and the result is infinity). One might reasonably expect both
x1
andx3
to be Negative Infinity .. however, onlyx1
is Negative Infinity.x3
is Positive Infinity, which is about as wrong as any answer could possibly be. This implies that double.Parse blatantly ignores the sign of zero. -
That's your opinion. Others (including me) would find it logical that zero cannot be negative. Some languages allow 2 different zeroes. I find it particularly annoying when x is negative when I expect it to be zero.
Well the problem is not so much that zero can't be negative, because zero can be negative in C#, if it has a floating point type. The problem I have with this is that it's inconsistent and weird that writing a certain number in the source and parsing it from a string give different results. Not even just some least-significant bit, but the sign. That's a pretty big deal.
-
I thought I knew, but I was wrong.
double x0 = 1 / 0.0;
double x1 = 1 / -0.0;
double x2 = 1 / double.Parse("0.0");
double x3 = 1 / double.Parse("-0.0");Obviously these are all going to be some sort of infinity (yes you can divide by zero[^], and the result is infinity). One might reasonably expect both
x1
andx3
to be Negative Infinity .. however, onlyx1
is Negative Infinity.x3
is Positive Infinity, which is about as wrong as any answer could possibly be. This implies that double.Parse blatantly ignores the sign of zero.Ah, C#, negative zeores in floating points but I can't say why the parser ignores it. Negative zeores exist in computer only? Ever heard of the term negative zeroes?
Beauty cannot be defined by abscissas and ordinates; neither are circles and ellipses created by their geometrical formulas. Carl von Clausewitz Source
-
I thought I knew, but I was wrong.
double x0 = 1 / 0.0;
double x1 = 1 / -0.0;
double x2 = 1 / double.Parse("0.0");
double x3 = 1 / double.Parse("-0.0");Obviously these are all going to be some sort of infinity (yes you can divide by zero[^], and the result is infinity). One might reasonably expect both
x1
andx3
to be Negative Infinity .. however, onlyx1
is Negative Infinity.x3
is Positive Infinity, which is about as wrong as any answer could possibly be. This implies that double.Parse blatantly ignores the sign of zero. -
Did you try this:
double y0 = -0.0;
double y1 = 1 / y0;Does it give +nfty or -nfty? I ask because your
x1
looks like this to me:double x1 = -1 * 1 / 0.0;
Greetings - Jacek
-
Well the problem is not so much that zero can't be negative, because zero can be negative in C#, if it has a floating point type. The problem I have with this is that it's inconsistent and weird that writing a certain number in the source and parsing it from a string give different results. Not even just some least-significant bit, but the sign. That's a pretty big deal.
I understand what you mean now, but i tried it on ideone.com and x3 is -Infinity :confused:
-
I understand what you mean now, but i tried it on ideone.com and x3 is -Infinity :confused:
-
That's your opinion. Others (including me) would find it logical that zero cannot be negative. Some languages allow 2 different zeroes. I find it particularly annoying when x is negative when I expect it to be zero.
Others may find it logical that zero cannot be positive. Seriously though, floating-point numbers are defined by an international standard (IEEE 754) that allows for +0 and -0. They have well defined meanings. Wiki[^] The problem here is that while the language respects these, double.Parse fails to.
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
I thought I knew, but I was wrong.
double x0 = 1 / 0.0;
double x1 = 1 / -0.0;
double x2 = 1 / double.Parse("0.0");
double x3 = 1 / double.Parse("-0.0");Obviously these are all going to be some sort of infinity (yes you can divide by zero[^], and the result is infinity). One might reasonably expect both
x1
andx3
to be Negative Infinity .. however, onlyx1
is Negative Infinity.x3
is Positive Infinity, which is about as wrong as any answer could possibly be. This implies that double.Parse blatantly ignores the sign of zero.Feds are gonna investigate and file a report on whoever has done this heinous crime ...