|
0/0 should throw a DivideByZeroException (which it does for integers).
And apparently 1/0 equals infinity.
Now what is it? NaN, infinity or just plain not possible?
Doesn't it sound weird (and, indeed, very wrong) that a NUMERIC type has a value "NOT A NUMBER"!?
Anyway, when I said "why would there even be a NaN anyway" I was referring to NaN in actual real life business cases that make sense and have practical use
|
|
|
|
|
I would recommend you to this article before you continue your rant about IEEE754.
|
|
|
|
|
Tried to read it once, but to me it makes as much sense as the whole NaN implementation: none whatsoever (and I admit my limited math skills are to blame).
However, I tried reading the NaN part and what they basically say is that in some edge cases you don't want computations to stop (throw exceptions) when some bogus values are inserted (e.g. divide by 0). The workaround without NaN would be to catch exceptions and simply try again. Unfortunately, every language handles exceptions differently so they standardized on NaN.
Awesome, they destroyed our numeric system to support some edge cases (correct me if I'm wrong)
Luckily .NET offers some sensible numeric types with int, long and decimal
Unfortunately, I'm currently working in JavaScript, with floating point arithmetic, where NaN is quite common, and 0.1 + 0.2 equals 0.30000000000000004 (yes, I know that's IEEE754, but that doesn't make it right)
|
|
|
|
|
Sander Rossel wrote: they destroyed our numeric system to support some edge cases
Any representation of real numbers in computer memory will destroy 'numeric system' since you're trying to represent infinite set with finite amount of memory.
Sander Rossel wrote: Luckily .NET offers some sensible numeric types with int, long and decimal
decimal comes with performance costs as it has no support in hardware so it might not be suitable as a replacement in fields that traditionally use floating point arithmetic. It is meant to be used for financial stuff since IEEE754 is not suitable for that purpose, so not everyone have to invent their own way of doing math.
Sander Rossel wrote: 0.1 + 0.2 equals 0.30000000000000004
That's the problem with converting real numbers between different bases.
|
|
|
|
|
Sander Rossel wrote: And apparently 1/0 equals infinity. No, it does not, and never has.
|
|
|
|
|
double x = 1;
double y = 0;
double z = x / y; Yes it does
I'm not making this stuff up, you know (IEEE does that).
|
|
|
|
|
No it doesn't, 1/0 is undefined (i.e NaN) and always has been. Various computer systems may try to represent it by some very large or very small value, but that does not alter the fact that it has no mathematical value.
|
|
|
|
|
Really man, I completely agree with you there, but .NET (and I guess IEEE) represents 1 / 0 as Infinity and 0 / 0 as NaN. And Infinity behaves different than NaN, so they're not the same (according to .NET/IEEE) no matter what we think of it
|
|
|
|
|
Sander Rossel wrote: .NET (and I guess IEEE) represents 1 / 0 as Infinity No, it does not, where on earth did you get this idea from? How exactly do you represent infinity as a number in a computer?
|
|
|
|
|
I got it from simply running the following code in C#...
double a = 1;
double b = 0;
double c = a / b; I'm seeing the result is Infinity right here on my screen and you telling me it isn't and never was
|
|
|
|
|
That's just a C# fudge. Mathematically that is not correct.
|
|
|
|
|
It is not just a C#, it is IEEE 754
And this is how you represented:
7ff0 0000 0000 000016 = Infinity
fff0 0000 0000 000016 = −Infinity
7fff ffff ffff ffff16 = NaN
Those first 12 bits correspond to the sign and exponent, and the values 7ff and fff are reserved constants with special meaning.
Why? I don't freaking know, I didn't invent IEEE 754. But anywhere you find double it is like that because it is standard, and it is even implemented in the CPU.
It is very easy to show it is not C#, see this JSFiddle[^].
Does it make mathematical sense? No. A number system that has a representation for not-a-number makes no sense.
---
Although I can argue that a number system with 1/0 = Infinity is possible, it would be a two-point compactification[^] of the real numbers to include -Infinity and Infinity*. Another system with 1/0 = Infinity is the Rieammn Sphere**, but that number system has only one Infinity and include the complex numbers.
*: To be clear, that means that you create a topological space where the infinite number line is embedded by a projection in a finite segment. Then the points at the extremes of the segment can't ever be reached, there is no real number low or high enough to reach those points. Then you label then "-Infinity" on the negative side and "Infinity" on the positive side. Clearly those points aren't real numbers, and they break traditional algebra, but they are numbers. Why would you want them? I don't know.
**: But I know for the Riemman Spehre, you can extend the real numbers to add the complex infinity point. This is embedding the complex plane in the surface of a unit sphere, such that the opposite point from 0 is never reached by any complex number. Then you label that point "Complex Infinity". Then you go to say that 1/0 = Complex Infinity, and 1 / Complex Infinity = 0 - now you can divide by infinity and solve integrations the old way. Yet, it also breaks algebra. Of course, this is problematic, and mathematicians left the idea in favor of Limits. The modern well-behaved solution (that doesn’t break algebra) is Hyperreals.
|
|
|
|
|
This is fun.
So what is the value of the interval between -infinity and infinity? Tee hee...
We're philosophical about power outages here. A.C. come, A.C. go.
|
|
|
|
|
The more I read on this subject, the more I regret not doing advanced maths when I was at school.
|
|
|
|
|
|
Theraot wrote: A number system that has a representation for not-a-number makes no sense. Thank you!
|
|
|
|
|
This is how you represent infinity in a computer:
a) For simple precision (32 bits), set sign = 0/1, mantis = 0x7FFFFF, exponent = 0xFF, and you get +/-INF.
b) Similar for double and extended precision.
This is how you set a NaN in simple precision:
Any number except +/-INF above, that has exponent = 0 or 0xFF is a NaN.
Gheorghe
|
|
|
|
|
|
1/0 is NOT infinity!
I know you've already stated you're weak at maths, but try to do some basic research before posting non sense like that!
1/x with x -> 0 that is something completely different though!
OK, I know I'm arguing with an idiot who actually thinks infinity is a number!
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
I KNOW 1/0 is nonsense and not infinity, but try telling that to C#[^]!
Then again 1/0 is also not NaN, it's just bogus and an Exception is the only correct outcome, but say that and people go all IEEE on your ass!
|
|
|
|
|
To my mind, the only reasonable operations with NaN are assigning an lvalue to NaN and comparing a value to NaN for equality and inequality. Any of the arithmetic operators ought to yield NaN (or throw an exception).
Come to think of it, the IEEE must have a formal document that describes all of this behavior. Pardon me while I JFGI... Ahh; typical. The formal document is only available to IEEE members who know the official circle jerk handshake. NaN - Wikipedia, the free encyclopedia[^] is a quick article that describes background and informally NaN's usage.
This article: IEEE Standard 754 Floating-Point[^] also has some discussion on NaN behavior.
Software Zen: delete this;
|
|
|
|
|
Sander Rossel wrote: Yes you can, and that's the point. Then be prepared to accept the consequences.
|
|
|
|
|
Sander Rossel wrote: so always treat it as smallest value, or always as biggest value or, better yet, throw an exception when comparing it to numbers.
If you know you have a scenario where NaN is in play, then test for the NaN and handle accordingly? You should not let a NaN produce an exception on purpose? Maybe I am not getting the big deal here, because I don't see this as a big deal.
|
|
|
|
|
And with that the case is more than closed.
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver
When I was six, there were no ones and zeroes - only zeroes. And not all of them worked. -- Ravi Bhavnani
|
|
|
|
|
More to the point, infinity is not a number.
|
|
|
|