Talk:Detect division by zero: Difference between revisions

m
added a section header to the first topic to properly place the table-of-contents (TOC) --- (this happens more often than one would think).
No edit summary
m (added a section header to the first topic to properly place the table-of-contents (TOC) --- (this happens more often than one would think).)
 
(6 intermediate revisions by 3 users not shown)
Line 1:
== division of zero by zero ==
 
Many of the solutions here simply check that the result is infinite. This will fail if the numerator is 0 too, since 0 / 0 is mathematically incalculable (many languages return NaN here).
 
Line 20 ⟶ 22:
:: According to the [http://en.wikipedia.org/wiki/Defined_and_undefined wikipedia] "In mathematics, defined and undefined are used to explain whether or not expressions have meaningful, sensible, and unambiguous values. Whether an expression has a meaningful value depends on the context of the expression. For example the value of 4 − 5 is undefined if a positive integer result is required." And the problem with 0/0 is the cardinality of the result, not the lack of any results. --[[User:Rdm|Rdm]] 11:37, 19 June 2010 (UTC)
::: I don't know of any conventional mathematical context in which "<math>\frac{1}{0}</math>" or "<math>\frac{0}{0}</math>" has a meaningful, sensible, and unambiguous value. —[[User:Underscore|Underscore]] ([[User talk:Underscore|Talk]]) 18:42, 19 June 2010 (UTC)
:::: I thought 1/0 was often accepted to represent an infinity, though I can agree that infinities are not necessarily sensible nor unambiguous. That said, mathematics seems capable of dealing with such subjects. --[[User:Rdm|Rdm]] 02:58, 20 June 2010 (UTC)
:::: Limits are such a context. <math>\lim_{n\rightarrow+0}\frac 10</math> ''converges to'' (positive) infinity. It's not ''actually'' a value per se. When performing operations and calculations this if often not done precisely (by handling the limits) but for the most part that doesn't really matter. Still, ∞ isn't part of the real numbers. —[[User:Hypftier|Johannes Rössel]] 09:27, 20 June 2010 (UTC)
::::: Ok, but everything in mathematics is based on context, though of course the interesting math is relevant in a wide variety of contexts. Nevertheless, we also have areas of mathematics where an operation logically could give any of an infinite set of results and for convenience we pick one of those results as the for that expression. One might argue that having the value of 0 for the principle value for 0/0 is not useful, but in my opinion this is akin to saying that 0 itself is not useful. Note, for example, that this approach would usually eliminate the need for knuth's "strong zero" approach at http://arxiv.org/PS_cache/math/pdf/9205/9205211v1.pdf Of course, exceptions can be constructed but they can be dealt with in much the same way as any other case that requires the use of a non-principal value. --[[User:Rdm|Rdm]] 15:02, 2 July 2010 (UTC)
 
 
== Choices in Javascript Implementation ==
 
: Can someone provide reasoning for the way JavaScript solution is implemented? To me it looks like it is simply passing back the JS result and returning 0 if the expression evaluates to NaN. It also return 0 for divByZero(4,'n'). I think we can all agree diving by a string is not 0 :). I wrote a solution but don't want to add it in case I'm not completely understanding the function :) My solution
function divzero(l,r) {
return ((l/r).toString() === 'Infinity' || (l/r).toString() === '-Infinity' || (l/r).toString() === 'NaN') ? "error" : l/r
}
Tested Chrome & Firefox, The methods used are in ECMA since JS 2.0. Tested with 4/2 return 2, 4/0 returns error, 4/-0 return error, 0,0 returns error, 0,n returns error, 0,4 returns 0
--[[User:Nycigor|Nycigor]] ([[User talk:Nycigor|talk]]) 00:02, 6 November 2015 (UTC)
 
:: The task asks that division by zero be detected, but leaves open what to do at that point. The decision to return zero should be seen not as detection but as an (arbitrary but silly) decision about what to do after detection. --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 14:40, 6 November 2015 (UTC)
 
== divides by zero ==
 
'''Math:'''
 
It's all fun and games until somebody divides by zero. &nbsp; &nbsp; &nbsp; -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 13:47, 30 November 2019 (UTC)