[proposal] :Allow divde by zero #5511
Replies: 7 comments 9 replies
-
For those that says this division has no meaning, why would you ever divide by 0, well why would you ever cast your type to object, but regardless it has a meaning in mathematics, and having this as an undefine behavior is like having a hole in value types after 'null' in our references which we know how many dollars it cost us. if people try to cast anything divided by zero back to its original type it should be seen as multiplying it by zero but compiler should say (warn/error) that you should be multiplying it by zero instead of casting it. |
Beta Was this translation helpful? Give feedback.
-
For floating point math dividing by zero produces infinity which is already represented in the language and runtime as |
Beta Was this translation helpful? Give feedback.
-
I think this is a grave misunderstanding of how mathematics works. Certainly one can define axiomatic systems under which division by 0 has a meaning, but there are an infinity of such axiomatic systems and none of them are special. In the vast majority of commonly used axiomatic systems which are close enough to our intuition for the concept number to be considered to define number systems, division by 0 does not have a meaning. If your research uses a rarer number system where it does, well good for you, but that does not change the fact that for the vast majority of number theories it does not. Computing tends to use number systems which are very different to those of mathematics. They match our intuitions about how numbers behave far less, but are much more efficiently implementable on physical machines. In these systems which are highly performance optimized allowing for special divided by 0 values is definitely a no go. |
Beta Was this translation helpful? Give feedback.
-
This seems very sensible. And it feels like semantics you could have by defining your own numeric type which would then know what this means and how to properly propagate it through all the operations you support. |
Beta Was this translation helpful? Give feedback.
-
Note: the language will definitely not at support for this unless the runtime adds a first class type for this and we feel there will be widespread use of this type. As an example, we have no current interest in adding language support for System.Half. |
Beta Was this translation helpful? Give feedback.
-
@Xyncgas as I said, this seems like a sensible abstraction. It would, however, likely be very niche. As such, it would be better served by a math library written for this purpose.
Yes. Scientists are first class citizens. However, so are many other groups. And, as mentioned above, this is a very niche feature. We are not likely to do such a feature that has such a small audience, and which can be solved through the use of a library. Thanks |
Beta Was this translation helpful? Give feedback.
-
As already stated, if you are using float or double division by zero already compiles and has a meaning. (1f / 0f = ∞f, 1d / 0d = ∞d). For the non floating point types division by zero is an error CS0020, and changing it would be a breaking change. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
There's meaning dividing things by zero in mathmatics (for one, I am dividing 0 in my research), but it's so hard for me to do this because it's undefined in c#, so instead I had to write hacks to do it.
the way you can do it is, instead of undefined, make it a special type when you divide numbers to zero, then when you multiply that number by zero it casts back. so this would be a good starting point. Ideally if a double was divided by zero the result should be pi_double which has the same length as zero and can perform other arithmetic normally in this type.
The essential part is to remember that this number has been divided by zero, and what number it was divided from. it should be representable in literal too like 12345P which means 12345/0
Beta Was this translation helpful? Give feedback.
All reactions