Slashdot Mirror


Ask Slashdot: What's the Harm In a Default Setting For Div By Zero?

New submitter CodeInspired writes: After 20 years of programming, I've decided I'm tired of checking for div by zero. Would there be any serious harm in allowing a system wide setting that said div by zero simply equals zero? Maybe it exists already, not sure. But I run into it all the time in every language I've worked with. Does anyone want their div by zero errors to result in anything other than zero?

1,067 comments

  1. Yes by Fwipp · · Score: 5, Insightful

    Does anyone want their div by zero errors to result in anything other than zero?

    Yes.

    1. Re:Yes by Venerable+Vegetable · · Score: 3, Insightful

      Right, I don't even... ehh... totally confused. It's not aprils fools right? Did this article get approved just to mock the submitter, or has Slashdot gone totally of the rails? Ok don't answer that last question.

      Maybe the submitter would care to submit an example of where he thinks it would be appropriate to equal divide by zero to zero, because I honestly don't know where to start.

    2. Re:Yes by Anonymous Coward · · Score: 0

      No, I don't want division by zero to give a result other than an logic error. Logic errors are a design flaw. There's something wrong with your code.

    3. Re:Yes by Anonymous Coward · · Score: 1

      Interestingly I've been through this. I work on a well known wearable device that uses a Cortex M4 processor. The default behavior in this processor was to DISABLE divide-by-zero exceptions (the hardware would instead return a 0). We were unaware of this early in development and when a bug related to this showed up, we changed the behavior to cause an actual fault when a div-by-zero occurred. This lead to interesting results. We use Keil (from ARM) as our compiler. It turns out they had a bug in the compiler It knew that the default behavior was to allow a divide-by-zero, so it optimized away our zero check before executing a chunk of code. This resulted in divide-by-zero crashes when we did a check to make sure the divisor was non-zero! Needless to say, they fixed the bug and gave us an updated compiler, but... it was a mess to say the least.

      Divide-by-zero is not possible, so it should not return a value. When you start to muddy those waters, you get into grey areas that result in unexpected bugs and, if it is not a standard, varying results from platform to platform and even compiler to compiler.

      No thank you. I'm happy to check for zero.

    4. Re:Yes by Anonymous Coward · · Score: 0

      The vast majority of people on slashdot know nothing about programing and even less about math...

    5. Re:Yes by Anonymous Coward · · Score: 0

      What's "insightful" with this response? Nothing.

    6. Re:Yes by TigerTime · · Score: 0

      But if you care, then you are checking for "divide by zero" anyway, and handling it a certain way, right? I don't think anyone WANTS to have their program crash. If a divide by zero is important, then just validate your data beforehand.

    7. Re:Yes by Anonymous Coward · · Score: 0

      Given that any non-zero value divided by zero is infinity, you will create some absurd and difficult to debug results by setting the result to zero. This is exactly why it cannot be allowed.

    8. Re:Yes by Anonymous Coward · · Score: 0

      Everything - every sane programmer under the sun wants their error conditions to actually be pointed out to them, rather than silently turned into nothingness.

    9. Re:Yes by Darinbob · · Score: 2

      This sounds so much like a beginning programmer question. Sorts of things I used to hear when being a teaching assistant. Too much effort, can this be simpler?

      Now in some cases, people may not care. There are a lot of cases where one ignores errors in real life. But lots of programmers love to crash at a moment's notice: sprinkle the code liberally with asserts rather than try to recover, let main() catch all errors and then print an error and exit, etc. However if you're ignoring an error you should abort the operation you were doing in a way that lets you continue gracefully.

      That means don't treat a divide-by-zero as zero ever, it means treat divide-by-zero as a notification that you should abort the operation you were doing. Continuing after a divide-by-zero error is just as bad as crashing. Throw away the answer rather than continue, otherwise it implies that the result of the calculation was irrelevant.

      One language I thought was interesting was "Icon", where the type of a result could be "failure", and any operation on failure results in another failure.

      Anyway, if someone wants to ignore divide-by-zero and to treat it as zero result, then they need a GOOD reason for it. And "it's tedious to check" is not at all a good reason.

    10. Re:Yes by Anonymous Coward · · Score: 0

      Not only yes, but almost universally yes. Dividing any positive value by zero yields infinity. Zero is the very far from correct. The only situation in which the correct answer could be zero is when you are dividing zero BY zero. In that instance the correct value of the result depends on the equation, and most of the time the correct answer still will not be zero. (e.g. For the equation y = 2x / x, when x is zero the answer is undefined, but you can also substitute a non-zero value that is infinitely close to zero and determine that "2" is the most correct value of y.)

    11. Re:Yes by ndrw · · Score: 2

      Then they can get the fuck off this web site. We don't need it to be everything to everyone. We need it to be news for nerds, stuff that matters. Nerds, by definition know something about programming and hopefully more about math.

    12. Re:Yes by Anonymous Coward · · Score: 0

      Does anyone want their div by zero errors to result in anything other than zero?

      Absolutely yes.

      Zero is the worst possible answer. There are bad answers, but this is the worst.

      (2^31)-1 maybe. That might be close enough to the correct answer-- infinity-- for many purposes.

    13. Re:Yes by Assmasher · · Score: 1

      This. Thank you.

      Please throw up when I do something this stupid so that I don't end up with inexplicable zeroes in the field.

      --
      Loading...
    14. Re:Yes by Anonymous Coward · · Score: 0

      The Hipsters are running the tech asylum.

    15. Re:Yes by rrr00bb5454 · · Score: 1

      The real problem is that the arguments to Divide are *not* of the exact same type. Assuming denominator and numerator are both multiplied times -1 to normalize them, the numerator is an integer, and the denominator is a positive non-zero number. In code, you should not be able to invoke a/b without being inside code that proves that b!=0 (ie: inside an if(b!=0), or b's type is non-zero integer. In functional languages, there would usually be a match or switch statement for this.

    16. Re:Yes by AthanasiusKircher · · Score: 5, Funny

      Right, I don't even... ehh... totally confused. It's not aprils fools right? Did this article get approved just to mock the submitter, or has Slashdot gone totally of the rails?

      Well, Slashdot recently implemented a new engine for approving articles, but there was a place in the code where one could end up dividing by zero, and they just decided to arbitrarily set that value to "post a random nonsensical Ask Slashdot question."

      So, Timothy screwed something up... and, well, rather than throwing up an exception -- VOILA... this story was approved!

      I'm surprised you haven't noticed this before -- I think it's how most "Ask Slashdot" questions get posted these days.

    17. Re:Yes by AK+Marc · · Score: 1

      This isn't about "easy". This is about error handling. What do you do when the answer is 7/0? Crash the program? Set the answer to some number? Why crash the program when we could come up with a meaningful answer?

    18. Re:Yes by Darinbob · · Score: 1

      you don't crash it. You either detect before hand that your divisor is 0, or else you have an exception handler to catch it (in C you would either modify your hardware exception handler if you're an embedded system, or in Unix you'd get a signal if the chip/compiler supported it).

      When you divide by zero then there is no meaningful answer. Instead you realize that 7/0 is bogus and fail the whole calculation. Instead of saying "the answer is 0" and letting the software continue doing arithmetic on that bogus number, you say "bzzt, wrong!" and recover.

      For example, you're plotting curves on a graphing calculator. Taking a long list of A,B values, dividing, placing on the chart. If you find out that Y is 0 you don't just assume the answer is zero and put a pixel there, instead you dump that entire pair and skip ahead to the next one. It didn't crash which is good, and it didn't place a pixel at a bogus location which is good, but it did verify that the values were correct before dividing which is a little bit of extra work.

      Now you don't need to always verify the divisor. Much of the time you know it will never be zero. Maybe the input was already validated earlier in a previous calculation, or validated when it was read in, or the value is a constant.

    19. Re:Yes by AaronW · · Score: 1

      I ran into a similar issue. I work on bootloaders for my company's 64-bit MIPS processors and due to size constraints disabled the normally enabled exception code (my bootloader has an exception handler). Anyway, it is usually easy to find the fault since the result is -1. It took me a while to figure that one out. If it were zero I probably never would have found the problem.

      --
      This post is encrypted twice with ROT-13. Documenting or attempting to crack this encryption is illegal.
    20. Re:Yes by Anonymous Coward · · Score: 0

      I would much rather that my program crash, than that it continue to execute with undefined or broken state.

      If I omit a check for a divide by zero it is an error. Giving it a default broken state does not change that it is an error. All it does is makes it harder to spot that error.

    21. Re:Yes by Spazmania · · Score: 1

      Div by zero means my program encountered an error. If it continues anyway, it could corrupt its database or misbehave in other destructive ways. Worse, it could provide the operator with incorrect results leading to real-world destruction.

      So yeah, I want divide by zero to throw an exception and I don't wish to ignore the exception.

      --
      Moderating "-1, Disagree" is simple censorship. Have the guts to post your opinion.
    22. Re:Yes by Anonymous Coward · · Score: 0

      Demodulation of AM signals.

    23. Re:Yes by Chrisq · · Score: 1

      Which is exactly why IEEE 754 defines 0/0 as Nan, a positive number divided by zero as + infinity, and a negative number divided by zero as - infinity.

    24. Re:Yes by stiebing.ja · · Score: 1

      a = b => a^2 = ab => a^2 b^2 = ab b^2 => (a + b)(a b) = b(a b) => a + b = b => 2b = b => 2 = 1

      --
      I lag
    25. Re:Yes by stiebing.ja · · Score: 1

      (...Dang non-Unicode sites...) a = b => a^2 = ab => a^2- b^2 = ab - b^2 => (a + b)(a - b) = b(a - b) => a + b = b => 2b = b => 2 = 1

      --
      I lag
    26. Re:Yes by Demonoid-Penguin · · Score: 1

      Does anyone want their div by zero errors to result in anything other than zero?

      Yes.

      Me too. For payrolls and billing. Payrolls we round the result down and subtract five. For billing we reverse the process. In all other cases the result is nothing.

    27. Re:Yes by Anonymous Coward · · Score: 0

      Theoritical math is different from real world physical actions. When you have 0 time to make an action, it does not become infinite when you use the time to divide something.

    28. Re:Yes by daedalus2097 · · Score: 1

      Yep, usually you want a divide by zero to end up as either 0 or infinity, and you need to be able to decide between them so it makes sense to handle it manually. No OS is gonna look good telling you that there's 0 second(s) left on your download when your transfer stalls.

    29. Re:Yes by michelcolman · · Score: 1

      I don't mind as long as they remain consistent and define multiplication of 0 times 0 to be a random number.

    30. Re:Yes by userw014 · · Score: 1

      Yes.
      I'd also wish hardware generated integer overflow exceptions as well.
      But if someone who doesn't understand that math on computers involves finite math and claims to be a programmer, I don't know what to say other than he's an ambulance chasing code weasel.
      May as well allow null pointer dereferences return 0. (Oh, yeah - the the old MIT Kerberos and X11 code assumed that and that's why the code base was crap for so long!)

    31. Re:Yes by Anonymous Coward · · Score: 0

      I want it to return 42.

    32. Re:Yes by ceoyoyo · · Score: 1

      Lots of math libraries do that, either returning nan or inf. In Python, for example, Numpy will happily divide by zero, but it gives you a warning and the result is inf. Any further operations on inf give you inf. Which is very handy because it means if you do an elementwise operation on a large array and one element is a divide by zero, the whole thing doesn't crash.

    33. Re:Yes by Toad-san · · Score: 1

      In div by zero, why is the zero considered an error? It may be a valid measurement.

      I've looked at a bunch of useful formulas, and can't find a single one where replacing ANY variable value with 0 would be wrong.

      http://www.infoplease.com/ipa/...
      https://en.wikibooks.org/wiki/...
      https://quizlet.com/3796199/ph...

      I haven't reviewed _all_ formulas, of course, and there might be places in code where disasters (or nonsensical results) might happen. Can anyone give me just one, please?

    34. Re:Yes by Anonymous Coward · · Score: 0

      I want it to be 1 (ie: 100%) more often than not. I develop plenty of scorecard style reports, and 0 in the denominator is not non-compliance.

      That is probably one of many examples where returning 0 in a divide by zero would mean confusion.

    35. Re: Yes by MichelleBalletto-Woo · · Score: 1

      Wait ... I teach math. Granted, not high levels, but math. Have you thought about why dividing by zero gives error messages? The divisor, in this case zero, tells into how many pieces you are dividing something. Dividing by 4, for example, means every single th8ng, like a pizza, is divided into 4 pieces. You cannot divide something into ZERO pieces .... you always have the ONE original thing. Logically, then, it would make more sense to say you are dividing by ONE, or if wanting to default to infinity, say it is a default by choise, not because the two ideas are equivalent. Just my math rant for the.day ;)

    36. Re:Yes by CodeInspired · · Score: 1

      I'm getting beat up pretty bad for posting this question. Perhaps deservingly. And I was also quite surprised to see the "your submission is on the front page of Slashdot!" email. But since you asked, let me try and explain a little about what I was thinking.

      First, I think everyone took it a bit too literally when I said "system wide setting". Maybe I phrased it wrong, but I wasn't suggesting that I flip a switch and suddenly everyone's code that's ever been written suddenly stops throwing div by zero errors. Clearly, as evidence by the many great comments in here, this would be a bad idea.

      But here is my scenario. I work with an medium sized application. We have thousands of users daily. Inside the application, it displays hundreds (possibly thousands) of statistics based on data from a database. A lot of them are fairly complicated to compute and a good portion of them involve some sort of averages. We update this application very frequently and include new statistics that our customers are asking for. We're a small shop and we try to write as many unit tests as we can, but with limited # of devs and a micro budget, we can't cover as much as we'd like. New features ALWAYS take priority.

      The data we receive for this application comes from about 25-30 different places and formats. Manually entered, csv files, xml files, email, faxes, etc. etc. We pretty much cater to anyone who wants to use our system and send us data, regardless of format.

      Now here's the issue. Our customers use our system in very different ways. For some, a certain set of key metrics are very important to them. Others could care less about the metrics. But the point is, most of these are NOT VERY IMPORTANT. It's just fancy features we roll out to try and make our app more appealing. When one crappy little statistic happens to divide by zero and we don't trap that scenario, the whole thing takes a shit. And that sucks for user experience.

      There's a very good chance that if the system is dividing by zero, it's because of the crappy data they sent us. In which case, the customer doesn't care or would understand if we told them it was off because of their data. But if they get a Div By Zero error message and can't move forward, they get really pissed.

      So, all I was really saying is, in MY APP, I want to be able to set a flag that says Div By Zero just equals zero. So when my lazy programmers (including myself), forget to test a scenario for the weekly build, we don't end up spending the next day scrambling to get a hotfix out because the system is crashing for a bunch of users.

      I know that doesn't fly very well here in the Slashdot crowd. And I've really enjoyed reading all the responses (even the derogatory ones). I was just frustrated and figured I probably wasn't the only one who has experienced this before. So I posted a dumb question... sue me.

    37. Re:Yes by SivDotnet · · Score: 1

      Hurrah! A real programmer actually responded to this. I was reading down the comments to see how far I could actually get until someone replied with the only possible answer to this question and it's a sad indictment of how slashdot has moved away from a real IT readership and is being used by complete air heads!

      It's not a math issue its a programming issue and you most definitely should not mask this sort of error, you should look at your code and eliminate any occurences where the programmer has allowed a div by zero to occur. Doing what the OP is suggesting is absolutely ridiculous.

      --
      Martley, Near Worcester UK.
    38. Re:Yes by mczak · · Score: 1

      FWIW, there are indeed languages where div by zero doesn't result in errors. Typically languages which can't throw exceptions. So, GLSL integer division gives an undefined result, as does the same in OpenCL. One reason of course is that these languages are meant to operate on vectors in hardware, and even if you could, you don't want to throw exceptions just for one element in the vector even though the rest of the vector is fine. Of course, unless you really don't care about the result in this case, you better make sure you recognize these zeros and do something to handle it (for instance, after doing the division, replace the result with zero or whatever if the divisor was zero). d3d10 shading language otoh gives you a defined result, but not zero (0xffffffff, for both quotient and remainder).

    39. Re:Yes by Venerable+Vegetable · · Score: 1

      I'm afraid your post won't get much notice here, buried a few comment layers deep off the front page. It's unfortunate that you didn't provide this background with your question, because it would probably have led to a more interesting discussion.

      Anyway, I think it has been sufficiently pointed out to you that the universe will come to an end if you equal divide by zero to zero. However, I do feel your frustration. I too work on reporting tools which have very unreliable inputs and making sure the program catches all the errors takes up a large chunk of my time. I have much respect for your position to try to cater to anyone.

      Yet it would still be a very bad idea. You just can't know what people will do with your statistics, even though you don't think they are important at the time you make them available. Most likely they will make decissions based on your statistics (otherwise why would they want them) and when they're not correct things can go very bad.

      As others pointed out, there are plenty of occasions where zero will be an acceptable solution, but this should always be a conscious decission.

    40. Re:Yes by lsatenstein · · Score: 1

      Yes

      about 50 years ago I worked with APL, It treated the following n/n = 1 for any perfectly eqal numbers (float, integer, bit, double...)

      If n,m were approaching zero, as even 0.000000009/0.000000009 it was still considered as 1.000000000 (or 1)
      So, whats the big deal?

      Of course, for n not equal to m and m, extremely close to zero, a zero divide error could be raised.
      APL had a variable called []CT (quad-ct ) representing global comparison tolerance. It affected divide by zero.

      QuadCT allowed comparisons of two floats to be considered equal if their difference was less than QuadCT. That decision affected n/m for floats.
      if abs(m - n) QuadCT then m =n and therefore n/m in this case was equal to 1.

      Just loved that decision in the language.

      --
      Leslie Satenstein Montreal Quebec Canada
    41. Re: Yes by Anonymous Coward · · Score: 0

      0 / 0 = anything (specially encoded value)
      Nonzero value / 0 = never (specially encoded value)

  2. Simple by Anonymous Coward · · Score: 5, Insightful

    It means your code is wrong. Who knows what led up to that /0 error.

    1. Re:Simple by Anonymous Coward · · Score: 0

      Sales chart lists all sales broken down by department. Electronics, hardware, etc. It also breaks it down further, hammers, table saws, etc. Hardware sold nothing last month. What percentage of that was hammers?

      Boom, a zero without any bad code.

    2. Re:Simple by Anonymous Coward · · Score: 1

      Bad question. There is no percentage.

    3. Re:Simple by Austerity+Empowers · · Score: 1

      What's the ratio of hammer sales to table saws, 0/0... is 0 the right answer? Infinity? 10?

      If I want to know the ratio of black pixels to white pixels for a set of images, and I get an all black image, is 0 the right answer? No, 0 is the wrongest answer.

      I think if you don't want to check by div 0, and div 0 is a possibility, you are asking the wrong question.

    4. Re:Simple by Anonymous Coward · · Score: 0

      Division by zero is a problem only in specific cases:

      0 is the only number with this property and, as a result, division by zero is undefined for real numbers and can produce a fatal condition called a "division by zero error" in computer programs.

      A real number includes the rationals and irrationals. 0/0 does not represent a "number", therefore it cannot be a rational or an irrational. It's NaN.

      That said, there are exceptions:

      There are, however, contexts in which division by zero can be considered as defined. For example, division by zero z/0 for z in C^*!=0 in the extended complex plane C-* is defined to be a quantity known as complex infinity. This definition expresses the fact that, for z!=0, lim_(w->0)z/w=infty (i.e., complex infinity). However, even though the formal statement 1/0=infty is permitted in C-*, note that this does not mean that 1=0infty. Zero does not have a multiplicative inverse under any circumstances.

    5. Re:Simple by Darinbob · · Score: 1

      How is that a divide-by-zero? If you had $1,000,000 in sales and hardware sold nothing then their ratio of sales is 0/1000000 and not 1000000/0.

    6. Re:Simple by blue+trane · · Score: 1

      Math can't handle the question, so censor the question. But natural language permits the question. Thus, natural language is more expressive than math. (See Chomsky's Hierarchy of Languages.)

    7. Re:Simple by tristes_tigres · · Score: 1

      Yep, well, it simiply does not mean that your code is wrong. There are valid reasons to divide by zero.

    8. Re:Simple by blue+trane · · Score: 1

      The question is fine. The answer should be, # of black pixels to no white pixels. That makes sense in natural language. Only math can't handle it, thus exemplifying math's inability to express real life situations that natural language handles without problem.

    9. Re:Simple by Anonymous Coward · · Score: 0

      Yep.

      After 20 years of programming, I have an utterly incompetent question to ask.

      This Ask Slashdot is so inane that there is no other reasonable explanation other than it being a troll submission. There is nothing even remotely interesting to debate about the merits of this question. The parent comment encapsulated 100% of the answer and reasoning behind it in a single line, without any need for excuses, corner cases, or special situations.

      The premise is bad, and if the submitter were serious, then the submitter should feel bad about asking in the first place. (And, the editors should feel bad about allowing this to the front page. This isn't even humorous; it's insulting. I feel bad for wasting 4 minutes to type this. Fuck Slashdot.)

    10. Re:Simple by Anonymous Coward · · Score: 0

      Arithmetically it may be incorrect, but logically it often makes sense to want divide by zero to equal zero.

      I can't find any examples because I had to write them with a conditional branch instead and since forgot about which block of code it was, but it was something like each number represented a different state, and current state divide equals this state minus that state would always yield the "correct" state transition if only / 0 would = 0, based on the way the logic was supposed to work and which numbers I assigned to which states.

      So when I was working through it I cursed that / 0 is an error and begrudgingly wrote a conditional or a switch or some bullcrap that didn't exploit the clever coincidence born of my intelligent arrangement of the numbers and moved on with my work.

    11. Re:Simple by Alien1024 · · Score: 1

      The answer is not zero. The answer is "no data".

    12. Re:Simple by Seatche · · Score: 1

      Example?

      --
      I'm bad with sayings, so just go live life for crying out loud.
    13. Re:Simple by AK+Marc · · Score: 1

      What's the ratio of hammer sales to table saws, 0/0... is 0 the right answer? Infinity? 10?

      The answer to all non-mathematicians is 0. The sales are all zero, so the answers are all zero.

      If I want to know the ratio of black pixels to white pixels for a set of images, and I get an all black image, is 0 the right answer? No, 0 is the wrongest answer.

      Ratio? x:y is a ratio. 1:0 is the correct ratio, and requires no divide by zero. You just present it in a more accurate manner.

      I think if you don't want to check by div 0, and div 0 is a possibility, you are asking the wrong question.

      What if you don't mind checking for div by zero, but that the answers are useful in some (or all) cases of div by zero, and you don't want to halt or refuse to let the user put in an all black image.

      Usability allows for div by zero, then gives a useful (even if not mathematically correct) answer.

    14. Re: Simple by Anonymous Coward · · Score: 0

      Im guessing this is wrong because I used waterfall to solve the problem instead of a sprint to rush a divide by zero error into production.

      ( Cost of Hammer * number of hammers sold) * (hardware percent of total* total)

    15. Re:Simple by John+Marter · · Score: 1

      That's not the answer the business side wants to hear. They just want a zero on the report.

    16. Re:Simple by mcelrath · · Score: 1

      This entire article makes me seriously question Slashdot as a hangout for anyone who passed high school. Anyone who asks this question should not be employed as a software engineer either.

      --
      1^2=1; (-1)^2=1; 1^2=(-1)^2; 1=-1; 1=0.
    17. Re:Simple by aybiss · · Score: 1

      I was correcting people anonymously but had to log in for this being 'insightful'.

      As I pointed out elsewhere, division by zero is something you might come across in demodulating AM signals.

      It's not the standards at Dice that are slipping around here guys.

      --
      It's OK Bender, there's no such thing as 2.
    18. Re:Simple by 91degrees · · Score: 1

      Not always. There are a few areas where this may happen - It's fairly common with vector normalisation (zero result does typically actually work here, because a zero length "normal vector" is invalid, so we can deal with that later), anything to do with user input (where we really want to deal with the error).

    19. Re:Simple by Anonymous Coward · · Score: 0

      No data? There's absolute data, so no data is not the correct answer

    20. Re:Simple by Dog-Cow · · Score: 1

      1^2=1; (-1)^2=1; 1^2=(-1)^2; 1=-1; 1=0.

      1^2=1; (-1)^2=1; 1^2=(-1)^2; 1=-1; 2=0.

    21. Re:Simple by jeremyp · · Score: 1

      Sales chart lists all sales broken down by department. Electronics, hardware, etc. It also breaks it down further, hammers, table saws, etc. Hardware sold nothing last month. What percentage of that was hammers?

      100%? 0%? 53.7%? The question is meaningless if you didn't sell anything at all. If your code doesn't handle the case where itemsSold == 0, it is bad code.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    22. Re:Simple by tristes_tigres · · Score: 1

      Eigenvalue finding by bisection using Sturm sequence.

    23. Re:Simple by PetiePooo · · Score: 1

      sqrt(1^2) does not imply 1, nor does sqrt((-1)^2) imply -1, they both could be either positive or negative: sqrt(1^2)=±1

      The last equality should appear as ±1=±1

      Congratulations; you've hit on another undefined answer in mathematics and exploited it to make the rest of the uneducated think you're smart.. or something.

    24. Re:Simple by Anonymous Coward · · Score: 0

      I didn't say what percentage of the overall sales were hammers. I said what percentage of hardware's sales were hammers. I also made no claim what so ever about what the answer should be. OP made a very simple statement (if you have a zero, something must be wrong further up), and I was refuting that simple statement. Nothing more.

    25. Re:Simple by Anonymous Coward · · Score: 0

      I never said the answer was zero. OP made a very simple statement (if there is a zero denominator, you must have done something wrong earlier in your code). I was simply refuting that statement. Nothing more.

    26. Re:Simple by Anonymous Coward · · Score: 0

      What's the ratio of hammer sales to table saws, 0/0... is 0 the right answer? Infinity? 10?

      I don't know, and I don't care, as it is irrelevant to my post. OP made a simple statement, and I was refuting that simple statement, nothing more.

      I think if you don't want to check by div 0, and div 0 is a possibility, you are asking the wrong question.

      That is pretty much my point. OP assumed that div by 0 should never be possible, and if it is, you did something wrong earlier in your code. I was demonstrating that it is possible to have to check for it without there being an issue earlier in your code.

    27. Re:Simple by Alien1024 · · Score: 1

      I think of it as a relational database,

      SELECT A.HammerSales / B.HardwareSales AS Answer
      FROM
          (
              SELECT Sum(Amount) AS HammerSales
              FROM SALES
              HAVING Item='Hammer' And MonthOfSale='201505'
          ) A ,
          (
              SELECT Sum(Amount) AS HardwareSales
              FROM SALES
              HAVING Department='Hardware' And MonthOfSale='201505'
          ) B

      It will not return zero if there are no sales at all for last month. It will return an empty dataset (i.e. no data).

    28. Re:Simple by Alien1024 · · Score: 1

      Bah. Invalid SQL of course. s/HAVING/WHERE as there's no GROUP BY.

    29. Re:Simple by lilrobbie · · Score: 1

      That makes sense in natural language. Only math can't handle it, thus exemplifying math's inability to express real life situations that natural language handles without problem.

      I've seen you repeat this phrase a few times now, but to paraphrase a good movie, I don't think it means what you believe it does.

      The question make sense in natural languages only because natural languages rely on the listener to divine the speaker's intent. I.e., Natural languages handle this issue by being ambiguous most of the time. I'm not sure that being deliberately vague and unclear is quite the advantage you're wanting it to be. Ever tried reading legalese? The advantage of natural languages isn't the language... it's the human processing unit that has accumulated years of experience in how to communicate with the language.

      Math can handle the question. It's just that most humans don't have enough interest or attention to detail to comprehend the answer...

  3. Bugs? by weilawei · · Score: 4, Informative

    Burning karma here to see if anyone else has the same problem. Mod offtopic if you like.

    New posts of mine aren't showing up for about half an hour typically. Do they need to be staff approved now or something?

    Second, on several front page stories, I no longer have the option to post. They say, "Nothing to see here. Move along" and "Archived discussion".

    I think the new design changes are pretty alright, but those two are breaking changes for me.

    1. Re:Bugs? by blue+trane · · Score: 4, Informative

      Titles are now partially obscured by the comment count and the classification icons. Screenshot: http://snag.gy/ciB02.jpg

    2. Re:Bugs? by aardvarkjoe · · Score: 4, Funny

      Didn't you hear? Slashdot is trying this cutting-edge "Agile Development" thing. The idea is that instead of testing your changes, you just make them directly on your production site and see what happens. It's the wave of the future!

      --

      How can we continue to believe in a just universe and freedom to eat crackers if we have no ale?
    3. Re:Bugs? by __aaclcg7560 · · Score: 1

      This is Slashdot. The person updating the production servers was probably screwing the pooch from marketing. Everything is fine now. Nothing to see here. Move along.

    4. Re: Bugs? by Anonymous Coward · · Score: 0

      It's funny because that's what a bunch of luddites I know think agile is. And they're so wrong. Bad agile maybe. But bad anything is bad.

    5. Re:Bugs? by damn_registrars · · Score: 2

      The idea is that instead of testing your changes, you just make them directly on your production site and see what happens

      Does that mean that slashdot is extremely cutting edge? They've been doing this for years!

      --
      Damn_registrars has no butt-hole. Damn_registrars has no use for a butt-hole.
    6. Re:Bugs? by Anonymous Coward · · Score: 1

      They also got rid of the "X comments" link at the bottom. Only reason I'm here now is that clicking on the headline luckily opened the story.

    7. Re:Bugs? by Anonymous Coward · · Score: 5, Insightful

      You think *you're* having problems. I'm seeing actual stories with titles like "Ask Slashdot: What's the Harm In a Default Setting For Div By Zero?"

    8. Re:Bugs? by RyoShin · · Score: 1

      Slashdot was in "read only"/maintenance mode earlier today (at least, that's what the site told me.) I assume it's still trying to catch up.

      I can't recall Slashdot going into maint. mode during the day even infrequently before Dice purchased them. Now it seems they do it once or thrice a week.

    9. Re:Bugs? by techno-vampire · · Score: 2

      I had the same experience. However, I've also found that clicking on the number of comments will get you to the discussion. I do wish that the webmonkies would give the crack-pipes back to the mods and stop uglifying the site.

      --
      Good, inexpensive web hosting
    10. Re:Bugs? by PopeRatzo · · Score: 2

      New posts of mine aren't showing up for about half an hour typically. Do they need to be staff approved now or something?

      Second, on several front page stories, I no longer have the option to post. They say, "Nothing to see here. Move along" and "Archived discussion".

      Slashdot functionality is like a guy who goes to a massage parlor.

      It comes and goes.

      --
      You are welcome on my lawn.
    11. Re: Bugs? by Anonymous Coward · · Score: 0

      It's not nice to badmouth your development staff like that.

    12. Re:Bugs? by Anonymous Coward · · Score: 0

      Is this why I have Chinese letters on my buttons? I'm not Chinese nor do I have a Chinese keyboard layout.

    13. Re:Bugs? by u38cg · · Score: 1
      Ah, you mean like Slashdot has always done?

      Also, yes, I know it's only 13 seconds since I hit reply. When you're as awesome as me, you don't *need* more time.

      --
      [FUCK BETA]
    14. Re:Bugs? by weilawei · · Score: 1

      Couldn't tell you. I am also not Chinese and do not have a Chinese keyboard layout. (My name is an Old English word, which still exists in modern English, albeit with a slightly different spelling.)

    15. Re:Bugs? by Anonymous Coward · · Score: 0

      CSB

      I used to work for a company that would reboot everything at 12 noon every Wednesday because that's when all the workers were supposed to go to lunch, but it was always a pain because I had to first call up a guy about 3000 miles away and make sure everyone was done and taking their lunch break.

      Oh, but that didn't include all the off-site sales people (in several time zones) who also used the system who didn't take their lunch at pre-determined times

      This was NOT a 24 hour shop, let alone 24/7. I suggested doing it during off-hours, but I think their reasoning was that they wanted someone there on -site in case there was a problem. If there had been a problem I would have had to login remotely from 3000 miles away. If I couldn't remotely login their "IT guy" there would have had to do what I asked him over the phone.....or we would have called IBM. It was a pretty stable system (AIX & Informix) so we never had problems with a simple reboot (and if we had, then it would have meant we actually had some other problem which we should deal with).

      We probably could have let it run for months but I'm not against a weekly reboot as long as it doesn't disrupt anyone.

      I'll stop right there before I go into some of the really insane shit that place did.

    16. Re:Bugs? by Anonymous Coward · · Score: 0

      Oh man! I didn't even notice your username. I was not trying to insinuate anything racist here. My bad!

  4. WTF is this shit? by Anonymous Coward · · Score: 3, Insightful

    Umm, wtf is this shit?

    1. Re:WTF is this shit? by Anonymous Coward · · Score: 0

      It's just that ... shit!

    2. Re:WTF is this shit? by __aaclcg7560 · · Score: 2

      A divide by zero error. Happens all the time.

  5. Sounds like a plan! by Whip · · Score: 5, Insightful

    "Rather than failing when an unexpected condition arises, I want all software on my system to continue running with a possibly invalid or meaningless internal state."

    Sure, what could go wrong?

    1. Re:Sounds like a plan! by Anonymous Coward · · Score: 4, Informative

      I won't mention names to hopefully dodge any lawyers lurking about, but "a friend" works in the airline industry and a certain commercial aircraft flight computer on receiving bad or missing data from the Inertial Reference System would happily go on reporting a value without indicating an error. Luckily, this friend became aware of the problem trying to resolve a CG issue before takeoff. Fun times.

    2. Re:Sounds like a plan! by RingDev · · Score: 1

      This is exactly the problem!

      Lets say the OP has a system that is designed to distribute money to a group of investors. He takes the money, divides it by the number of investors, distributes that money, then he reduce the account balance by the amount tagged for distribution.

      So he has $1 mil, and a list of 4 investors. Each investor gets $250k and his account drops $1 mil.

      Now lets say that the list of investors is empty, the code runs, and distributes $0 to no one, then his account drops by $1 mil.

      Sure seems like there should have been an exception in there!

      -Rick

      --
      "Most people in the U.S. wouldn't know they live in a tyrannical state if it walked up and grabbed their junk." - MyFirs
    3. Re:Sounds like a plan! by Dunbal · · Score: 3, Insightful

      Yeah but for some people "if(investors >= 1)" is hard.

      --
      Seven puppies were harmed during the making of this post.
    4. Re:Sounds like a plan! by Anonymous Coward · · Score: 1

      @php

    5. Re:Sounds like a plan! by The+MAZZTer · · Score: 1

      ON ERROR RESUME NEXT

    6. Re:Sounds like a plan! by Anonymous Coward · · Score: 0

      CG? Center of gravity? Control group? Computer generated? Complete GIGO?

      Some of us aren't pilots. Please explain yourself and spell out jargon the first use.

    7. Re:Sounds like a plan! by Anonymous Coward · · Score: 0

      I can tell you what can go wrong. There is a kind of PLC that actually thinks that x/0 == 0. A place where I used to work used a PLC of that particular type to build a controller for a production facility. There was a variable that was assumed during development to always have a reasonably big value and it was used like this: result := FUDGE_FACTOR / sensor_input; One day the variable was zero and hence the result zero and that made the machine assume that it didn't need to do anything even though something was going terribly wrong.
      Incidentally, during later investigation it turned out that if the machine had given maximum force instead everything would have gone more or less all right, but that's not the point. The point is that setting x/0 to 0, or any value really, masks a bug. In this case the sensor input should have been checked for dangerously low values and possibly an alarm should have been raised, but in fact the machine did something wrong, which could lead to production errors or the facility grinding to a halt. Fortunately the facility didn't produce anything important, as far as I'm concerned. But what if something like this were to happen in a nuclear facility?
      It would have been much better if the PLC had crashed, because then the watchdog would have raised an alarm and reset the PLC. In this particular case a second sensor readout might even have fixed the problem, because these things fluctuate and a tiny but non-zero value would have let the machine do the right thing. But the important bit is the alarm. To be able to fix problems you have to know what the problems are and as much detail about them as possible. Trying to hide that a problem occurs then is the absolute worst you can do.

    8. Re:Sounds like a plan! by david_thornley · · Score: 1

      I've heard of military computers being designed so that, in "battle mode", they would never abort or throw an exception or whatever. The idea is that the result might be wrong, but not supplying a result is always wrong. I think the Navy, in particular, is still a bit sensitive about late 1942, when the battleship USS South Dakota suffered a power failure and was under bombardment by three Japanese warships for ten minutes while being unable to do anything about it.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    9. Re:Sounds like a plan! by Anonymous Coward · · Score: 0

      That can actually work better than one might expect. See this paper: Fan Long, Stelios Sidiroglou-Douskos, Martin Rinard, "Automatic Runtime Error Repair and Containment via Recovery Shepherding", PLDI 2014, http://people.csail.mit.edu/st...

      Quote from the introduction:

      We present a new system, RCV, which enables applications to
      recover from divide-by-zero and null-dereference errors, continue
      on with their normal execution path, and productively serve the
      needs of their users despite the presence of such errors. RCV
      replaces the standard divide-by-zero (SIGFPE) and segmentation
      violation (SIGSEGV) signal handlers with its own handlers. RCV's
      divide-by-zero handler manufactures the default value of zero as
      the result of the divide, then returns back to the application to
      continue normal execution after the instruction that triggered the
      divide-by-zero error.
      For writes via an address close to zero, RCVâ(TM)s segmentation
      violation handler discards the write. For reads via an address close
      to zero, RCVâ(TM)s handler manufactures the default value of zero as
      the result of the read. For function calls via a function pointer
      close to zero, the handler skips the call (such calls often correspond
      to method invocations on a null object). In all cases RCV then
      returns back to the application to continue normal execution after
      the instruction that triggered the segmentation violation.

      The interesting thing is, this keeps running programs longer than you might think, and the results often aren't noticeable in the sense that the program produces the "right" output.

    10. Re:Sounds like a plan! by Darinbob · · Score: 1

      But programming is haaaard! Can't we make it simpler? Oh ya, and pay me more because I thought of the idea to make it simpler.

    11. Re:Sounds like a plan! by tristes_tigres · · Score: 1

      Yes, you (almost always) do NOT want to throw exceptions on division by zero. Doing otherwise resulted in billion-dollar explosion of Arian 5 rocket.

    12. Re:Sounds like a plan! by Whip · · Score: 1

      This can be the right thing to do *if the entire (sub)system is designed to accommodate it*. But I certainly would not want, say, ICBM targeting code to drop a missile on my house because someone decided that continuing to run in the face of an error was better than aborting...

    13. Re:Sounds like a plan! by MikeKD · · Score: 1

      But programming is haaaard!

      Let's go shopping!

    14. Re:Sounds like a plan! by Whip · · Score: 1

      Actually, the Ariane 5 loss was caused by an overflow, not a divide by zero (see first paragraph at https://en.wikipedia.org/?titl...).

      Even if it were a divide by zero problem, though, the error was in the code handling flight trajectory computations; I dare say an uncaught error in the code computing your trajectory is going to put the rocket somewhere that you don't want it, regardless. So you fail in one way or you fail in a different way. I doubt there's any case where ignoring a divide by zero error (or an overflow error) would actually keep the rocket on a correct trajectory.

    15. Re:Sounds like a plan! by Anonymous Coward · · Score: 0

      Yes, you (almost always) do NOT want to throw exceptions on division by zero. Doing otherwise resulted in billion-dollar explosion of Arian 5 rocket.

      No, the Ariane 5 debacle was caused by the fact that they reused the code from Ariane 4. That code had certain checks suppressed, because the developers made assumptions about the maximum speed etc that were valid for the Mark 4 but no longer valid for the larger rocket. The control system ended up in (what it thought was) an invalid state, so self-destructed.

    16. Re:Sounds like a plan! by tristes_tigres · · Score: 1

      No, you are wrong that the error was in the code handling flight trajectory computations. It was in the part of software that was needed before the launch, and not at all during the flight. The results of that computation were not needed for guidance, and yet unhandled exception caused the controller to crash.

      Secondly, you are wrong when you assume that the division by zero is necessarily an error. There are valid and useful numerical algorithms that rely on division by zero being well-defined operation.

    17. Re:Sounds like a plan! by tristes_tigres · · Score: 1

      The code that generated an exception was not useful by the time rocket left the launch pad. Yet because the designers, like you, incorrectly thought that division by zero must throw an exception, the flight controller crashed, and with it, the rocket.

    18. Re: Sounds like a plan! by Anonymous Coward · · Score: 0

      How would it have gone if instead it tried x/0=x instead of 0?

    19. Re:Sounds like a plan! by Whip · · Score: 1

      Fair enough on the specifics, but you did miss my entire point. :/

    20. Re:Sounds like a plan! by i.r.id10t · · Score: 1

      Divide by investors, and then loop thru the investors and remove teh 250k (or whatever chunk) for each one, just like looping thru the records/rows returned by a db query. But, just like if your db query returns no results, doing something like

      while ($row=$dbhandle->fetch_row()){ // call some function to transfer money from investment account // to investors' accounts
          xferMoney($amount,$srcAccount,$destAccount);
      }

      That xferMoney() function would never run, because there is no row to fetch from the db results.

      (sorry, was fixing some old PHP code earlier today, so I'm still kinda in that mindset....)

      --
      Don't blame me, I voted for Kodos
    21. Re:Sounds like a plan! by tristes_tigres · · Score: 1

      Well, no, I did not. If the result Inf occurs in computations that must be passed to control mechanisms, it must be caught at this point, and not where it occured. Throwing exception on arithmetic operation is bad idea that seems good if you do not think about it carefully. Which authors of IEEE754 did, and produced a very good standard.

    22. Re:Sounds like a plan! by amxcoder · · Score: 1

      Now lets say that the list of investors is empty, the code runs, and distributes $0 to no one, then his account drops by $1 mil.

      Ok, I understand everything up to the "and distributes $0 to no one", and as weird as that sounds, would technically be correct. But why would the computer system then deduct $1M from the account afterwards if no money was distributed?

      Seems to me, no matter how many investors there are, that the amount deducted would be equal to the sum of each investor payout. So if there is no investors, and no money is disbursed, then the sum of that money dispersed, would be $0.00 and no money would be deducted from the account.

      Why would you use the original amount in the account to base what the account withdawal total would be, that is asking for problems even if there are investors. For instance if you devide the amount by a number of investors, and the results end up having fractions of cents involved, you'd want to round to the whole cent, and then add up what each investor is getting to account for the rounding of fractional cents. Otherwise, you would have pennies disappearing from the account and into thin air.

    23. Re:Sounds like a plan! by Anonymous Coward · · Score: 0

      Reminds me of a 90's joke ... how do you pronounce IEEE on an airplane designed on a Genuine Intel(tm) Pentium(r) Process?

      AYYEEEEEEE!!!!

      (For the kids out there, first generation pentiums had an obscure floating point bug that was big news for about 3 months.)

    24. Re:Sounds like a plan! by martas · · Score: 1

      well yeah, of course you could work around it if your system always defined x/0=0. in fact, if all your code is written correctly, and checks for division by zero before it ever happens instead of using built-in exception handling, then you shouldn't even notice how your system handles x/0. but the point is if you fuck it up, you at least want to know you fucked it up.

    25. Re:Sounds like a plan! by RingDev · · Score: 1

      Why would >I do that?

      I wouldn't.

      But the type of idiot who suggests that X/0 should return 0 instead of throwing an exception quite likely would. ;)

      -Rick

      --
      "Most people in the U.S. wouldn't know they live in a tyrannical state if it walked up and grabbed their junk." - MyFirs
    26. Re:Sounds like a plan! by Anonymous Coward · · Score: 0

      Then the branch to do the disbursment should not run at all.

    27. Re:Sounds like a plan! by Anonymous Coward · · Score: 0

      I see you're a Perl programmer...

    28. Re:Sounds like a plan! by Anonymous Coward · · Score: 0

      Ok, I understand everything up to the "and distributes $0 to no one", and as weird as that sounds, would technically be correct. But why would the computer system then deduct $1M from the account afterwards if no money was distributed?

      Because the "stop right there, no money was distributed" exception was replaced with a zero.

      Seems to me, no matter how many investors there are, that the amount deducted would be equal to the sum of each investor payout.

      Like anybody wastes time writing the code to calculate the sum, when the total payout is already a parameter to the function...

    29. Re:Sounds like a plan! by jeremyp · · Score: 1

      This is better because, if there are three investors, the extra cent won't mysteriously disappear into the void.

      On the other hand, if the loop runs zero times, no division has occurred at all which is sort of what we mean when we say you can't divide by zero.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    30. Re:Sounds like a plan! by Anonymous Coward · · Score: 0

      I try to use an "except DivByZero" but either work.

    31. Re: Sounds like a plan! by Anonymous Coward · · Score: 0

      It would have exerted some force, but probably not enough to prevent the problem. Mind you, even if evaluating x/0 as x would have solved the problem in this case, it still would be a bad idea, because it won't always help and like evaluating it as 0, it hides the presence of a bug.
      I'll state it again because it bears repeating: ‘To be able to fix problems you have to know what the problems are and as much detail about them as possible. Trying to hide that a problem occurs then is the absolute worst you can do.’

    32. Re:Sounds like a plan! by PincushionMan · · Score: 1

      Oh man, why did you have to post 4GL (or ABL or whatever they call it today) into this topic!

      Okay, I'll bite. I prefer FIND LAST table OF otherTable WHERE aDate = ? NO-LOCK NO-ERROR in a FOR EACH loop with lots of BUFFERs to the same table, myself. It means I have to wrap each table access in IF AVAILABLE statements (shortened to IF AVAIL table THEN DO:). Thanks for the tip, though.

    33. Re:Sounds like a plan! by Anonymous Coward · · Score: 0

      And i have needed exactly x/0 == 0, when calculating time left for actions. Actually i've never used anything else, because i've never needed to and i have absolutely needed it to be 0. That's how i know i'm out of time or whatever. The fact that there was no safety limits is another problem and should've been taken care of wether x/0 gives 0, INF, NAN, x, FU or anything else.

    34. Re:Sounds like a plan! by Anonymous Coward · · Score: 0

      "Rather than failing when an unexpected condition arises, I want all software on my system to continue running with a possibly invalid or meaningless internal state."

      I suspect this was one of the design goals of PHP.

    35. Re:Sounds like a plan! by TaleSpinner · · Score: 1

      We invented a special programming language to implement this paradigm. It's called "C." It's quite popular, actually. Responsible for almost every security problem in the world, but popular...

  6. Idiot by Anonymous Coward · · Score: 0

    You are an idiot!!

    1. Re:Idiot by frovingslosh · · Score: 5, Interesting

      Absolute idiot. Reminds me of a time years ago when I was working at a University computer center. Despite my cultivated angry looks, a student came up to me with a printout and asked "Uh, what does this mean?" I said, "Oh, you want me to read it to you? It says: Error -divide by zero on line 50." I got a blank stare. So after a minute I further said" It means you are trying to divide by zero on line 50 of your code, which of course you can't do." That was responded to with another blank stare. So I said "look, here is line 50. See those two variables that you are multiplying together and then dividing into those other numbers? One of them must be reaching zero. Since you can't divide by zero the computer is trying to tell you that something has gone wrong. Go back, print out the variables inside the loop right before line 50 and see which one reaches zero. Then figure out why it is zero." The student said nothing and wandered away, apparently unhappy that I just didn't write the code for her.

      A few days later one of the student operators who worked for me there said to me "Remember that girl that you tried to help with the divide by zero problem? She's getting a B+ in her computer science class." Such is the state of the education system. This was a while ago, but as far as I can tell, and this post indicates, things have no gotten any better.

      No, you don't just ignore this problem and you absolutely don't put a system wide rule in effect to ignore the problem. If you get such an error it indicates a very fundamental problem wit the logic of the program. It is not trivial, and in real world situations could be deadly.

      And you don't just return the largest system number rather than zero, as some other idiots have suggested. That would be just as wrong and just as dangerous.

      And if you are really seeing this error often, I strongly suggest a change in profession to a short order chef.

      --
      I'm an American. I love this country and the freedoms that we used to have.
    2. Re:Idiot by Noah+Haders · · Score: 1

      I think this is supposed to be spelled, "your an idiot!!"

    3. Re:Idiot by mr_mischief · · Score: 1

      Hey, let's not get hasty. Short order chef is a challenging job with lots of details. You can't just default everyone to cheese omelettes when you can't be assed to check the validity of the table ticket. Clearly this guy needs to work on his attention to detail first. Maybe mopper or busser.

    4. Re:Idiot by Anonymous Coward · · Score: 0

      No, you don't just ignore this problem and you absolutely don't put a system wide rule in effect to ignore the problem. If you get such an error it indicates a very fundamental problem wit the logic of the program. It is not trivial, and in real world situations could be deadly.

      Can you provide an example. Other then it being logically wrong and hurting your feelings. What are the real world examples of when this could lead to such deadly results?

    5. Re:Idiot by kosmosik · · Score: 1

      > No, you don't just ignore this problem and you absolutely don't put a system wide
      > rule in effect to ignore the problem. If you get such an error it indicates a very
      > fundamental problem wit the logic of the program. It is not trivial, and in real world
      > situations could be deadly.

      First of all I don't object you - you just don't divide by zero cause math. And it is it.

      But could you please describe one (or more if you wish) situation in which such behavior could be deadly?

      Seriously I briefly thinked about it in this context (programing) and can't think of any serious practical aplication. I know I feel bad about myself about it... but I really don't know.

    6. Re:Idiot by Anonymous Coward · · Score: 1

      What are the real world examples of when this could lead to such deadly results?

      Airplane autpilot computes speed from GPS timestamp and position, using difference between now and previous measurement, synced to 1 Hz PPS. Leap second hits, autopilot divides by zero, thinks it's not moving, guns the engines, hijinks ensue.

    7. Re:Idiot by Pharago · · Score: 1

      well you can always make a class that encapsulates a number type and give it a default number when it approaches zero, like a very very tiny epsilon, but yeah there are systems where even that is not actually a choice, like some small microprocessors with minimun language support

      someone said intel made a chip that could finish an infinite loop in 5 minutes, I don't don't think it would be long before they make one that divides by zero and gives you a meaningful result

    8. Re:Idiot by frovingslosh · · Score: 1

      I don't want the software/firmware to hide this blatant error in self driving cars, aircraft control systems, air traffic control systems, medical devices (including but not limited to medicine delivery and radiation based treatment and diagnosis), automated or remote controlled military weapons, or even the ABS or power train systems of my current car while I'm driving it in heavy traffic at 70 mph or so. And that is just for starters and a few fairly obvious examples. But pretty much any process control system that affect the real world (meaning all of them) could be capable of inflicting dangers if completely out of control. Other examples could range from anything from automated amusement park rides to computerized legal records (unless you think it is a fun and safe thing to have a dozen over eager SWAT yahoos bust down your door and start getting agressive with their automatic weapons because your finger prints came up a match for who they were looking for, a match that was caused by a complete lack of any similarity in the fingerprints and a divide by zero error).

      --
      I'm an American. I love this country and the freedoms that we used to have.
    9. Re:Idiot by frovingslosh · · Score: 1

      See my response to the same question above. Are you by chance a time traveler from the 1800's or earlier? Because I don't see how anyone born since the end of WWII could even ask that question.

      --
      I'm an American. I love this country and the freedoms that we used to have.
    10. Re:Idiot by Lord+Ender · · Score: 1

      It's believable that someone could get a B+ in an entry level CS class even without a good understanding of arithmetic. Entry level CS is more about understanding flow control and variables than it is about mathematics.

      If she got a B+ in Calculus, that would be concerning. And since all university-level CS programs require Calculus, the student in your story likely never graduated... unless this was a for-profit college, perhaps.

      --
      A slashdotter who didn't build his own computer is like a Jedi who didn't build his own lightsaber.
    11. Re:Idiot by Anonymous Coward · · Score: 0

      If this is your attitude towards a lack of understanding, and if you think cultivating angry looks is part of teaching, then you are saying all we need to know about the problems with our educational system. Apparently all the people who aren't "idiots" and could actually help the "idiots"...are self-centered jerks instead.

      Thanks for passing your "wisdom" on to the next generation of clueless airheads who learn to not ask questions because they'll just get belittled anyway so operate on ignorance instead, and angry jerks, so many of whom learned from you how to better cultivate a deathstare and tear people down when they're bothering you, instead of helping, encouraging, or doing ANY thing that might actually make these problems better instead of worse for anyone involved.

      Did it occur to you that the girl might not understand the mathematical issue of divide by zero? Seems like you told her everything she OBVIOUSLY already knew and intentionally omitted the part that might have actually clued her in. And why? Because "she should already know that because of prerequisite course X"? Doesn't matter what she "should" know if she doesn't, and you did nothing but perpetuate her ignorance and encourage her to learn more about how to succeed in ignorance. Seems to me you could have taken a minute or two and help her learn/relearn, and maybe get a tiny shred of that "maybe I'm not stupid" feeling, but instead you chose to take your frustration and bitterness out on her in the type of cold manipulative way that you knew an instructor could get away with. I think you "should already know" how to treat human beings, and regard it as a prerequisite for being a teacher.

      I take this moment to thank the powers that be for the patient teachers I had, and that I learned CS and higher math autodidactically until I worked straight into a software engineering job, all without "learning" how obviously stupid I am from some pompous prick whose guidance would have landed me in a miserable dead-end kitchen job. But then you'd probably be fine with that since it's where I belong, right?

    12. Re:Idiot by blue+trane · · Score: 1, Insightful

      The problem lies in the inexpressivity of math, not in the student. Division by zero happens naturally and it is math's problem if it can't deal with it. Natural language can deal with it, nature deals with it. Math fails to express nature adequately.

      Example: water flows over an area of land and divides itself evenly: so 1 cubic meter of water / 1 square meter of flat land. Now the land erodes and becomes 0 square meters. The water doesn't have to resort to error-handling code, it knows what to do, it flows on. But math gets hung up at the point when the land disappears, your code throws an error, and you have to handle that. But nature doesn't throw any error, it handles division by zero naturally and seamlessly. Again, math fails to describe nature very well.

    13. Re:Idiot by Anonymous Coward · · Score: 0

      WTF, how did this nonsense get modded up to 3?

      Maths doesn't get hung up. It's your inadequate mathematical model of the real world that got hung up.

    14. Re:Idiot by khallow · · Score: 1

      Did it occur to you that the girl might not understand the mathematical issue of divide by zero? Seems like you told her everything she OBVIOUSLY already knew and intentionally omitted the part that might have actually clued her in. And why? Because "she should already know that because of prerequisite course X"? Doesn't matter what she "should" know if she doesn't, and you did nothing but perpetuate her ignorance and encourage her to learn more about how to succeed in ignorance. Seems to me you could have taken a minute or two and help her learn/relearn, and maybe get a tiny shred of that "maybe I'm not stupid" feeling, but instead you chose to take your frustration and bitterness out on her in the type of cold manipulative way that you knew an instructor could get away with. I think you "should already know" how to treat human beings, and regard it as a prerequisite for being a teacher.

      Except this guy apparently was not an instructor. Part of the college experience is learning who not to approach for advice and instruction.

    15. Re:Idiot by Anonymous Coward · · Score: 0

      Math is abstract, it doesn't describe anything except math. Physics and other sciences use math to construct models to describe nature, but that's not quite the same thing.

    16. Re:Idiot by Anonymous Coward · · Score: 0

      Personally I think it's the best troll I've seen in a while

    17. Re:Idiot by dcollins · · Score: 1

      The major difference here is that in the first scenario the water stops in the sink, while in the second scenario it doesn't (so no division actually occurred). Every scenario you can think of will have this same problem; in your second version the material will have not been consumed, and you'll be in a situation of still needing to deal with it or pass it on, which is totally unlike the first case.

      Reflect on why this is literally called an "overflow" error.

      --
      We know where leadership by an anti-intellectual "strongman" who scapegoats minorities and likes boisterous rallies goes
    18. Re:Idiot by Anonymous Coward · · Score: 0

      But math gets hung up at the point when the land disappears, your code throws an error, and you have to handle that. But nature doesn't throw any error, it handles division by zero naturally and seamlessly. Again, math fails to describe nature very well.

      Nature wouldn't handle your problem well either, you just state that the water "flows on". I ask you were does it flow? There is nothing in your problem description that would describe the area around the land, the description is incomplete for the case 0 square meter and assumes no interaction with the case square meter > 0, in essence you have an "if(square meter > 0) then divide else do nothing" in your problem, something math and computers are very well capable of handling.

      Also I have never seen a natural stream of water that would tower over eroding land until there was no land left - which is what you describe.

    19. Re:Idiot by Anonymous Coward · · Score: 0

      What are black holes?

    20. Re:Idiot by Anonymous Coward · · Score: 0

      It's nice you replied to that post, as the title seems to suit you well, too.

      For some, going through school seems to be a long period of unresolved bewilderment.

    21. Re:Idiot by Anonymous Coward · · Score: 0

      An to explain myself.

      Dear blue,

      The water doesn't calculate anything. It just flows, so it does need to check for errors or anything. WE calculate, and when we put a variable there for that land area, we assume it exists. Because we model the nature to understand it. When the land erodes, the area becomes zero, disappears, and the calculation we used is no longer defined. And this is exactly what math tells us by NOT defining div/0. That our model is wrong, and it should be perfected. It is telling us exactly what we need, it perfectly describes the actual event in nature: the structure of the phenomenon has changed, so it needs to be addresed.

    22. Re:Idiot by jeremyp · · Score: 1

      They are regions of space-time from which even light isn't fast enough to escape. Einstein's General Theory of Relativity predicts a singularity at the centre of a black hole i.e. a non zero amount of mass is squished into zero volume. This seems impossible so most people think that GR breaks down in such extreme conditions and we need a new quantum theory of gravity.

      i.e. the division by zero is an indication that the model is wrong.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    23. Re:Idiot by Anonymous Coward · · Score: 0

      Bullshit.

      If there's no land (area 0) there's no water to flow over it. Then, it doesn't make sense anymore to ask for the amount of water per square meter of flat land.
      Saying that "water knows what to do" is bullshit.

    24. Re:Idiot by elgatozorbas · · Score: 1

      Again, math fails to describe nature very well.

      Maths is perfectly capable to describe nature. Insofar as we understand nature (physics), our description uses maths. The problem is in crappy programming. No more, no less.

    25. Re:Idiot by Anonymous Coward · · Score: 0

      Math DOES express it quit well.

      Division by zero never occurs in the real world - the closest it comes is what is believed to happen in a black hole... And even then it is labelled "undefined".

      Water doesn't divide itself at all. It just spreads out due to gravity.

      And one cubic meter of anything isn't divided by 1 square meter... And dividing by no land doesn't have any meaning. In the case of the earth - there is still land underneath - and it is still 1 meter, just lower.

      Math describes nature quite well. It is your understanding of nature that is at fault.

    26. Re:Idiot by jeremyp · · Score: 1

      Imagine a cruise control in a car. Let's say that speed is measured (this may be the way it is really done, but it is speculation) by monitoring a point on the wheel and every time it passes the vertical a subroutine runs that calculates the time difference by using the system clock time now and the last time the subroutine ran and then the speed by dividing the circumference of the wheel by the time difference.

      If on two runs, the system clock reports the same time, I can think of two possibilities:

      - the system clock is broken
      - the wheel is rotating so fast that the system clock does not have enough resolution.

      Would you prefer the subroutine to report the speed as 0 thereby causing the cruise control to put the pedal to the metal; "really really fast" thereby causing the cruise control to slam on the breaks, or at least cut all power; or "I don't know how fast we are going" thereby causing the cruise control to disengage, perhaps with a warning to the human driver?

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    27. Re:Idiot by Ihlosi · · Score: 1
      Would you prefer the subroutine to report the speed as 0

      Yes. Because other parts of the cruise control algorithm can recognize a speed of zero as a point where the cruise control should not be operating at all and disengage it.

      The other options would be:

      Report an arbitrary value. This leads to horrible results as the arbitrary value may be below the set speed, but still in a range where the cruise control operates.

      Report the maximum value. This may lead to funny results if the programmer did not pay close attention to signed/unsigned datatypes.

      Do random stuff, crash, require restart before cruise control can be re-engaged: This doesn't immediately lead to horrible results, but to lots of unhappy customers wondering why their car needs resets/power cycling like their Windows computer does.

    28. Re:Idiot by Ihlosi · · Score: 1
      It is not trivial, and in real world situations could be deadly.

      Not ignoring the problem could be deadly, too, or at least very costly. It all depends on the application.

      Why do you think ARM put a mode in their CPUs where they just return zero on a division by zero? Does ARM leave their CPU design to idiots? I don't think so.

    29. Re:Idiot by Anonymous Coward · · Score: 0

      In your example how does the finite water actually get on to 0 square meters of land? Assuming a simple square, your 0 sq meters has a perimeter of 0. Therefore you cannot push a non-zero amount of water onto it. Alternatively you could reword the problem as - for every square meter of land, how deep is the water. Well if you have no square meters of water, then the first part of your sentence is not true, so the consequent second part is ignored.

      Math is easily expressible enough to represent reality, (cite any physics, or other quantitative-science book). The problem is that your mental model of what is going on is not valid as the area goes to 0 meters. Division by zero does not happen naturally in the world, in the same way and for the same reason that a/b doesn't have a finite answer as b goes to 0.

    30. Re:Idiot by Agent0013 · · Score: 1

      The problem lies in the inexpressivity of math, not in the student. Division by zero happens naturally and it is math's problem if it can't deal with it. Natural language can deal with it, nature deals with it. Math fails to express nature adequately.

      Example: water flows over an area of land and divides itself evenly: so 1 cubic meter of water / 1 square meter of flat land. Now the land erodes and becomes 0 square meters. The water doesn't have to resort to error-handling code, it knows what to do, it flows on. But math gets hung up at the point when the land disappears, your code throws an error, and you have to handle that. But nature doesn't throw any error, it handles division by zero naturally and seamlessly. Again, math fails to describe nature very well.

      This is some pretty unthinking logic you have going on here. How can land erode away to nothing. Is the Earth a flat plate sitting in space and once it erodes away there is nothing there but a hole? You do realize that underneath the land, there is more land right?

      If your land is slowly eroding into a channel, then the area is getting smaller. As it gets very narrow the water divides by a smaller and smaller area of land showing the depth to be getting bigger. Once the channel gets to zero width, there is nowhere for the water to go, so it can't be zero depth or even infinite depth, it is a question that makes no sense. If a channel in the real world got infinitely narrow, it would make more sense in the real world that the water would flow over the land that made up the channel's sides, but that is outside the division equation you stated with. That was dividing to find the depth of the water within the channel, once the channel is gone you have to redefine the equation to use another parcel of land.

      And if we go to the example where there is a hole into space through the flat earth, then it also makes no sense as there is no depth to water falling through a hole into nothing. It can't spread out onto land that isn't there.

      --

      -- ssoorrrryy,, dduupplleexx sswwiittcchh oonn.. -Quote found on actual fortune cookie.
    31. Re:Idiot by Agent0013 · · Score: 1

      Just give them the ID10T form and move on to other things.

      --

      -- ssoorrrryy,, dduupplleexx sswwiittcchh oonn.. -Quote found on actual fortune cookie.
    32. Re:Idiot by Anonymous Coward · · Score: 0

      Maybe I'm missing something but I'm pretty sure that’s not how erosion works (obviously assuming the crab people haven’t hollowed the planet out, making the Earth's surface paper thin)

      All dickery aside, I would be interested to see if there were examples of division by zero in nature

    33. Re:Idiot by Anonymous Coward · · Score: 0

      Okeydoke Mister Rodgers.

    34. Re:Idiot by Anonymous Coward · · Score: 0

      In this case
      \lim_{land->0}water/land = +\inf
      there is a mathematical solution because both the dividend and divisor are positive. But I still wonder what you are trying to calculate in your example. Why would you want to calculate the flow of water over land in the case that there is no land left? The answer is positive infinity, but does it mean anything practically?

    35. Re:Idiot by kosmosik · · Score: 1

      I don't know why are you hostile? :) If you could describe a situation in which allowing divide by zero would be deadly. I don't disagree with you - I AGREE - YOU DONT DIVIDE BY ZERO - BASIC MATH. But also I wonder how one can explain this to another by example on how it could be deadly (a airplane example, nuclear powerplant maybe)?

    36. Re:Idiot by Anonymous Coward · · Score: 0

      Professor Fish is that you ???

  7. Makes no sense by Anonymous Coward · · Score: 0

    Division by zero makes no sense, you can't tell how many times there is zero in a number. If your complex algorithm happens to divide a number by zero, it sometimes makes no sense, which you should want to avoid.

  8. The Simplest Answer... by __aaclcg7560 · · Score: 1

    According to my electronics instructor, if we designed a circuit that divides by zero the Universe would explode.

    1. Re:The Simplest Answer... by Anonymous Coward · · Score: 1

      According to my electronics instructor, if we designed a circuit that divides by zero the Universe would explode.

      Prove It!

      Besides, there is no harm in designing a circuit that divides by zero... Now building it would be another matter...

    2. Re:The Simplest Answer... by __aaclcg7560 · · Score: 4, Insightful

      Perhaps the Big Bang was a divide by zero error? That would explain a lot.

    3. Re:The Simplest Answer... by Moof123 · · Score: 3, Insightful

      Usually it just lets the magic smoke out. A divide by zero is usually called a short circuit and makes a lot of heat for a short period of time, after that you get the smell of the magic smoke.

    4. Re:The Simplest Answer... by __aaclcg7560 · · Score: 1

      I love the smell of brunt plastic in the morning. :/

  9. And how do you know if there's an error then? by CSG_SurferDude · · Score: 5, Insightful

    So how do you know if you had an error if you return "0" for a divide by 0 error? Now you have a whole 'nother set of problems to code around.

    1. Re:And how do you know if there's an error then? by Dadoo · · Score: 1

      Now you have a whole 'nother set of problems to code around.

      https://www.youtube.com/watch?...

      --
      Sit, Ubuntu, sit. Good dog.
    2. Re:And how do you know if there's an error then? by Dunbal · · Score: 1

      "How?" said Miss Pearce obediently, but without enthisiasm.

      "By writing down what the answer is!" exclaimed Dirk. "And here it is!" He slapped the piece of paper triumphantly and sat back with a satisfied smile.

      Miss Pearce looked at it dumbly.

      "With the result," continued Dirk, "that I am now able to turn my mind to fresh and intriguing problems, like, for instance..."

      He took the piece of paper covered with its aimless squiggles and doodlings, and held it up to her.

      "What language," he said in a low, dark voice, "is this written in?"

      Miss Pearce continued to look at it dumbly.

      Dirk flung the piece of paper down, put his feet up on the table, and threw his head back with his hands behind it.

      "You see what I have done?" he asked the ceiling, which seemed to flinch slightly at being yanked so suddenly into the conversation. "I have transformed the problem from an intractably difficult and possibly quite insoluble conundrum into a mere linguistic puzzle. Albeit," he muttered, aftera long moment of silent pondering, "an intractably difficult and possibly insoluble one."

      Apologies to Douglas Adams - Dirk Gently's Holistic Detective Agency.

      --
      Seven puppies were harmed during the making of this post.
    3. Re: And how do you know if there's an error then? by Anonymous Coward · · Score: 0

      As far as i know zero is not a valid result when I divide anything other than zero itself. In other words if the division of x> 0 returns zero I know there is an error. Then I can raise an exception :)

    4. Re:And how do you know if there's an error then? by Darinbob · · Score: 1

      The thing is, if you get a crash with "divide by zero" as the result then it's easy to see where this happened and then follow the path back to see where the ultimate cause originated. But if the divide-by-zero error is ignored and code continues on, then the code may crash much later in time and the cause may be extremely difficult to track down, or you may enter an infinite loop even.

      Save a few seconds of coding time by not checking versus wasting weeks trying to figure out why things are behaving unpredictably in the field.

    5. Re:And how do you know if there's an error then? by Anonymous Coward · · Score: 0

      Yeah... Oracle DB doesn't differentiate between a null value, and an empty string...

      It's... terrible....

  10. I want my division by zero errors to be errors by Lumpio- · · Score: 5, Insightful

    Because that usually means I'm trying to do something that's mathematically meaningless and I'd rather handle the special case than silently get a meaningless result.

    1. Re:I want my division by zero errors to be errors by TopherC · · Score: 4, Interesting

      I agree here. One easy example is computing an average: add up the numbers and divide by N. What if you have no numbers to average and N == 0? That doesn't mean the average is zero, it means you don't have an average. You always have to check for /0 errors, not because you want to keep the program from crashing but because you need to handle all the special cases. It's usually (not always) better to crash to alert you to an un-handled condition than to pretend nothing is wrong.

      Should all null pointer exceptions or segfaults be handled quietly in some arbitrary way, in order to make software more "robust?"

    2. Re: I want my division by zero errors to be errors by Anonymous Coward · · Score: 0

      If you want to assign a value to x/0, make it the address of a NULL pointer. Oh, wait...

    3. Re:I want my division by zero errors to be errors by gnupun · · Score: 1

      Well in Java, integer div by zero causes an ArithmeticException, whereas div by a floating-point zero results in +/-Infinity but no exception. Why should only integer code generate exceptions and not floating point code? Do floating point errors not matter?

      I think this not generating an exception has something to do with the huge range of numbers floating point types have compared to integers. But integers are quite big now, so int32 or int64 (signed integers) should have compile time option to return INT_MAX or INT_MIN instead of generating an exception. Unsigned integers should still generate an exception.

    4. Re:I want my division by zero errors to be errors by Anonymous Coward · · Score: 0

      Java failed to follow parts of the IEEE Standard 754. Specifically, you should have been able to trap divide by zero.

    5. Re:I want my division by zero errors to be errors by tristes_tigres · · Score: 1

      Wrong wrong wrong misguided and wrong again. division of non-zero by zero is quite meaningful and is defined by IEEE standard for floating point arithmetic to return infinity (wtih appropriate sign depending on the signs of the zero and numerator).

      In the rare cases when exception is needed IEEE compliant fp math implementation provides mechanism for it

    6. Re:I want my division by zero errors to be errors by Lumpio- · · Score: 1

      And how many times exactly have you been happy to get "Infinity" as a result? Pretty much every time I've gotten that there has been an error in my logic. IEEE can define division by zero to return 42 for all I care, but on the mathematical level I don't believe there is a universally good definition for it. Sometimes infinity can kind of make sense (e.g. the slope of a vertical line), but not universally. Therefore, I vote for undefined.

    7. Re:I want my division by zero errors to be errors by gnupun · · Score: 1

      And in almost 20 years of its existence, how many Java programmers have complained about not being able to trap divide by zero in floating point? Java has already implemented a default value (+/-infinity) for floating point divide by zeros, as requested by the submitter of this /. story, and it's a success. Let's face it, returning +/- infinity has huge benefits in code simplicity. And therefore the same thing should be done for signed integers.

      In a typical case, the int div-by-zero should return MAX_INT or MIN_INT. Down the line, garbage results caused by this div by zero alert the programmer to find the bug and fix it. As you can see, no div by zero exception handlers peppered throughout your code base.

      Let's look at the catastrophes caused by integer/floating point exceptions:

      Ariane 5 explosion:

      A data conversion from 64-bit floating point value to 16-bit signed integer value to be stored in a variable representing horizontal bias caused a processor trap (operand error)[29] because the floating point value was too large to be represented by a 16-bit signed integer.

      USS Yorktown

      Smart ship USS Yorktown was left dead in the water in 1997 for nearly 3 hours after a divide by zero error.

      I think a default divide by zero value would have prevented this.

    8. Re:I want my division by zero errors to be errors by tristes_tigres · · Score: 1

      Fortunately, your vote did not count when IEEE754 was created by the top numerical experts. Unfortunately, far too many programmers are voefully ignorant about proper FP math.

      > And how many times exactly have you been happy to get "Infinity" as a result?
      > Pretty much every time I've gotten that there has been an error in my logic.

      I believe you that there're lots of errors in your logic. One of them is ignoring mathematical fact that 1/0=Inf as per IEEE standard implemented in hardware by (virtually) all modern processors

    9. Re:I want my division by zero errors to be errors by Chris+Mattern · · Score: 2

      Well in Java, integer div by zero causes an ArithmeticException, whereas div by a floating-point zero results in +/-Infinity but no exception. Why should only integer code generate exceptions and not floating point code? Do floating point errors not matter?

      Because while 0/0 is undefined and an error everywhere, 1/0 is indeed infinity. Floating point has a representation for infinity, so you get that back. Integer types have no representation for infinity, so you get back an error instead. INT_MAX and INT_MIN are not infinity and would be dangerous incorrect to treat them as such, no matter how large their magnitude.

    10. Re:I want my division by zero errors to be errors by Archangel+Michael · · Score: 1

      Sanity check before averaging. If the number of items in a set to be averaged = 0 then don't run that code as it is useless.

      I prefer preemptive sanity checks before processing to avoid errors in the first place. You check for 0 BEFORE you divide, as it usually points to some other problem (besides math), in the case above, a null set.

      --
      Agent K: A *person* is smart. People are dumb, stupid, panicky animals, and you know it.
    11. Re:I want my division by zero errors to be errors by Lumpio- · · Score: 1

      CPU implementations have nothing to do with general mathematics D: Please stop confusing the two.

    12. Re:I want my division by zero errors to be errors by gnupun · · Score: 1

      1/0 is indeed infinity.

      No, it's undefined.

      The 754 model encourages robust programs. It is intended not only for numerical analysts but also for spreadsheet users, database systems, or even coffee pots. The propagation rules for NaNs and infinities allow inconsequential exceptions to vanish. Similarly, gradual underflow maintains error properties over a precision's range.

      http://stackoverflow.com/quest...

      The IEEE 754 model treats 0 as very small positive numbers, resulting in infinity when you do divide by zero. Of course, that hack results in much more robust and safer programs as you don't have to deal with (dozens/hundreds) of exceptions in a program.

      INT_MAX and INT_MIN are not infinity and would be dangerous incorrect to treat them as such

      It is a very rare program that has INT_MAX/INT_MIN as valid values. If your program even reaches close to INT32_MAX/MIN, you usually change the type of variable to a signed 64 bit variable. So, as with IEEE 754, we should have a default value for div by zero by int32 or int64 to allow "inconsequential exceptions to vanish."

    13. Re:I want my division by zero errors to be errors by Anonymous Coward · · Score: 0

      Robust means "it doesn't crash and I don't seem to care about what it does do", right? I mean, I'm trying to access to memory through an unset pointer... It's pointing to some memory, perform the operation there! I'm trying to perform mathematically impossible operations... Lets just set the answer to 0! I'm trying to index a list of size 0... Why not just perform those operations on the first memory that you do find!

      The software doesn't crash (which is good), it just performs unknown and untestable functions at unknowable locations on your hard drive (which is presumably better).

    14. Re:I want my division by zero errors to be errors by Seatche · · Score: 1

      Interesting point that null and 0 are not the same thing. In multiplication and division, 0, 1, and infinity are special in a non-linear world. In ratio's, we tie the linear (1+2) to the non-linear (1/2 + 2/1 = 2.5). The 1 is the identifier, rather than the add-on. The zero is only treated in the numerator. The infinity results in answers equal to infinity in the numerator, or infinitely close to zero when in the denominator, assuming it is not in both (lol). What if we had it wrong? What if 1 (ONE) was the weird one in division? It's weird that everything between 0 and 1 go to infinity, when in the denominator. What if something divided by zero (nothing) equaled the numerator, and anything divided by 1 went to infinity ? This, in my view, would make more sense, since the 1 is the identifier bit in multiplication, but zero (add nothing to something) is the identifier bit in the linear. It just makes sense that you would have two permutations of weirdness between the linear and non-linear, that don't add up. The math would be a little weird, however. 1/0 = 1*1. 1/1=NULL/UNDEFINED/Infinity. I'm probably wrong and can be proven so. I just remember as a kid thinking, "If I take a shoe, and divide it by nothing, I have my shoe. If I divide it by one, what the heck do I have? I think I came up with infinity." Oh well. Dividing by zero sounds absurd, until II see the source code and ran it.

      --
      I'm bad with sayings, so just go live life for crying out loud.
    15. Re:I want my division by zero errors to be errors by Immerman · · Score: 1

      >1/0 is indeed infinity.

      Is it? 1/+0 = +inf, but 1/-0 = -inf, VERY different results (consider the graph of 1/x where x varies from -1 to +1). And dividing by "neutral zero" should thus be either both or neither, an impossible situation, hence it MUST be undefined. (unless you're assuming a number system where +inf=-inf, but that's getting rather esoteric)

      And if you're taking limits as you approach a discontinuity, 0/0 may well be perfectly well behaved. Consider x/x - it equals 1 at all points *except* x=0, so it could be considered reasonable to consider it to equal 1 when x=0 as well. Of course as 2x/x remains constant at 2, so there can't be any general "solution" to 0/0

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    16. Re:I want my division by zero errors to be errors by Anonymous Coward · · Score: 0

      There is a result for division by zero: NAN "Not A Number". Those who think x/0 should have some specific value (like 0) can simply do "if (result==NAN) result=0.0;"

      Null pointer and segfaults can be handled - one way of handling them is to resume execution after the trapping instruction. This yields a robust uncrashable application - but garbage in surely yields garbage out in this case.

    17. Re:I want my division by zero errors to be errors by pe1rxq · · Score: 1

      No, just NO.

      Getting inf or -inf out of floating point actually makes sense: It is not just exactly zero but a whole range of very small numbers which give similar results and are treated as 'limits as x approaches 0'.

      Integer numbers and arithmetic are exact and although INT_MAX might be large these days it is still not anywhere near infinity and just does not make any sense at all.
      And having signed and unsigned behave differently also does not make any sense at all.
      Your compile time option might as well be named '-foutput-random-instructions'

      --
      Secure messaging: http://quickmsg.vreeken.net/
    18. Re:I want my division by zero errors to be errors by tristes_tigres · · Score: 1

      Please, do not use your ignorance as an argument

    19. Re:I want my division by zero errors to be errors by david_thornley · · Score: 1

      Java uses an IEEE standard for floating point, which includes NaN (Not a Number) and Inf (infinity) values. Further arithmetic operations will leave these as NaNs and Infs. Therefore, if you introduce one of these in a string of calculations, the result won't be a number, and you can figure it out from there. Java uses twos-complement binary integers. There are no special values, and even if you did designate a special value (the most negative number, say), ordinary arithmetic would change that value into a legitimate one. The only thing it can do to signal a problem is to throw.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    20. Re:I want my division by zero errors to be errors by gnupun · · Score: 1

      A more robust solution would be using the highest bit in the variable to denote integer NaN. That would reduce your signed int32 into a signed 31 bit integer, the unsigned 32 bit var would become unsigned 31 bits, the signed 64-bit would become signed 63-bit integer and so on.

      -iNaN = iNaN
      iNaN + var -> iNaN
      iNaN - var -> iNaN
      iNaN * var -> iNaN
      iNaN / var -> iNaN
      iNaN | var -> iNaN
      iNaN & var -> iNaN
      iNaN ^ var -> iNaN
      ~iNaN -> iNaN

      where var is either a valid integer or an iNaN.

      But the more I think about it, it seems there are very few instances where we have integer divBy0 in a real program. Since most divide instructions belong to equations that are usually implemented in floating point code, there is no need to have any type of integer NaN.

    21. Re:I want my division by zero errors to be errors by Anonymous Coward · · Score: 0

      you must be new here.

    22. Re:I want my division by zero errors to be errors by Anonymous Coward · · Score: 0

      I just looked at Wikipedia's article on IEEE 754, and it looks to me like div by a floating point zero also throws the exception. But all five defined exceptions also return a default value. So if what you say is true, Java is just ignoring the exception thrown by the hardware FP processor.

    23. Re:I want my division by zero errors to be errors by lilrobbie · · Score: 1

      Should all null pointer exceptions or segfaults be handled quietly in some arbitrary way, in order to make software more "robust?"

      Random trivia: Objective-C does exactly this - http://blog.imaginea.com/sendi...

  11. Security, security, security by Anonymous Coward · · Score: 1

    The real question is when I trigger a divide by zero, is my process in a secure state or an insecure state? If malformed input previously triggered a crash, did we just convert a denial of service attack to a full elevation of privilege attack?

  12. Well... by TaleSpinner · · Score: 4, Interesting

    ...aside from the fact that it's completely wrong I can't see a problem with it.

    1. Re:Well... by michelcolman · · Score: 1

      Neither do I, as long as they remain consistent and let 0 times 0 generate a random number.

  13. Infinity by Anonymous Coward · · Score: 5, Insightful

    I think infinity makes a bit more sense than zero. And max is the closest thing to infinity.

    1. Re:Infinity by Anonymous Coward · · Score: 1

      Mathmatically both are correct and everything inbetween.

    2. Re:Infinity by joeblog · · Score: 4, Informative

      When you have 0/0, you hit two "obvious" but contradictory rules in basic algebra:

      Rule one: anything multiplied by zero is zero
      Rule two: anything divided by itself is one

      Mathematicians don't know which rule has precedence for 0/0, so there's no way a dumb machine can figure it out, which is why most programing languages just throw an exception if zero is the denominator.

      --
      If it works, it's obsolete
    3. Re:Infinity by Verdatum · · Score: 1
      Ooooo, orrrrrrr, how about negative infinity? after all, 1/-.0000000000000000000000000001 is really close to that....

      Or wait, how about "Not a Number" because that is the only way to resolve jump-discontinuity.

    4. Re:Infinity by dissy · · Score: 4, Interesting

      When you have 0/0, you hit two "obvious" but contradictory rules in basic algebra:

      Rule one: anything multiplied by zero is zero
      Rule two: anything divided by itself is one

      But divide by zero isn't covered by either of those two rules of algebra.

      Asking what is X divided by zero is no different than asking what is Y plus red, or what is Z times pineapple.

      I say focus on a proper mathematical answer for multiplying by blue first, and then apply it to the equally nonsensical divide by zero question.

    5. Re:Infinity by lenart · · Score: 5, Informative

      Mathematically, the result is undefined. So neither is correct. Nor is anything inbetween.

    6. Re:Infinity by Anonymous Coward · · Score: 0

      What if blue = a pixel value? Then "multiplying by blue" has a "proper mathematical answer" and divide by zero is solved!

    7. Re:Infinity by spitzak · · Score: 3, Informative

      Actually IEEE floating point has a signed zero (+0 and -0 are different values) to solve exactly that. If x is positive, x/+0 is +infinity, x/-0 is -infinity. 0/0 (with any type of 0) returns NaN.

      However I believe the article was talking about *integer* division by zero, not floating point.

    8. Re:Infinity by Anonymous Coward · · Score: 0

      I assume the entire question is about integer math, because division by 0 is a non-issue in floating point. OP could just turn of NaN signalling and check the result after processing.

    9. Re:Infinity by Anonymous Coward · · Score: 1

      Mathmatically both are [as] correct and everything inbetween.

    10. Re:Infinity by joeblog · · Score: 3, Informative

      Let me rewrite that as:

      Rule 1: 0*X (where X = 1/0)
      Rule 2: X/X (where X = 0)

      I've had this argument often with APL fans who don't get that as obvious as 0/0 = 1 may sound, it's not mathematically sound.

      --
      If it works, it's obsolete
    11. Re:Infinity by Verdatum · · Score: 2
      it approaches infinity if you start at one and get closer and closer and closer to 0. N/.00000001 is pretty high.

      But it approaches negative infinity if you start at -1 and get closer and closer and closer to 0. N/-.00000000001 is pretty low.

      because of this discontinuity...the largest discontinuity possible in fact, the actual value of N/0 cannot be any of these compromises. It has to not exist.

    12. Re:Infinity by Samantha+Wright · · Score: 4, Insightful

      More importantly is what happens when you graph it: the limit of 1/x as x approaches zero is discontiguous. It's positive infinity when descending on the positive numbers, but negative infinity when ascending from the negatives. No one value can represent both!

      --
      Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
    13. Re:Infinity by Anonymous Coward · · Score: 0

      And negative infinity makes just as much sense as positive infinity.

    14. Re:Infinity by Anonymous Coward · · Score: 0

      Depends. Div by zero error is not the same as 0/0. The first you can give as +Inf (or -Inf), which are valid floating point numbers. 0/0 could be NaN.

    15. Re:Infinity by khallow · · Score: 5, Insightful

      Mathematicians don't know which rule has precedence for 0/0

      No, mathematicians known that there is no consistent number which would be an answer for 0/0. For example, take any number r and consider the fraction (rx)/x. For x not zero, it evaluates to r. Set x to zero and there's an argument that 0/0 should be r. But r wasn't special so you have an arbitrary argument with no special value of r indicated as the natural value of 0/0.

      Similarly, if you consider the fraction x/(x^2), you get an argument that 0/0 should be infinite (plus or negative depending on whether you approach zero from the positive side or negative). In other words, 0/0 is indeterminate with the value, if any, depending on how you approach 0/0.

    16. Re:Infinity by ShanghaiBill · · Score: 4, Insightful

      Mathematicians don't know which rule has precedence for 0/0

      In many situations, you can use L'Hopital's Rule to resolve 0/0. But a properly written program should never get in a situation of dividing by zero, and this is one of the dumbest "Ask Slashdot" questions in a while. Masking the interrupt makes about as much sense as driving blindfolded so you don't see the people you are running over.

    17. Re:Infinity by amicusNYCL · · Score: 1

      Ooooo, orrrrrrr, how about negative infinity? after all, 1/-.0000000000000000000000000001 is really close to that....

      That's preposterous. 1/-.0000000000000000000000000001 is infinitely far from negative infinity.

      --
      "Our two-party system is like a bowl of shit looking at itself in a mirror." - Lewis Black
    18. Re:Infinity by khallow · · Score: 1

      Asking what is X divided by zero is no different than asking what is Y plus red, or what is Z times pineapple.

      Actually these do make more sense. After all, energy is terms of dimensional units (such as kg m^2/s^2) which are qualitatively no different than red or pineapple. They just have far broader application in the real world. And Z times pineapple is a thing you can do. Y plus red may or may not make sense in this regard (for example, if Y is a multiple of red to begin with).

    19. Re:Infinity by khallow · · Score: 5, Insightful

      How about evaluating 0/(0*0) versus (0/0)/0? Assuming 0/0=1 gives you inconsistent outcomes unless you're willing to sacrifice associativity of multiplication and division.

    20. Re:Infinity by rwa2 · · Score: 4, Informative

      When you have 0/0, you hit two "obvious" but contradictory rules in basic algebra:

      Rule one: anything multiplied by zero is zero
      Rule two: anything divided by itself is one

      Mathematicians don't know which rule has precedence for 0/0, so there's no way a dumb machine can figure it out, which is why most programing languages just throw an exception if zero is the denominator.

      It's mathematically possible to do some form of 0/0 using limits and the calculus.

      lim x->0 x/x = 1

      Also lets you do some interesting other things, like:

      lim x->0 x^2/x = 2
      lim x->0 sin(x) / x = 1

      Shouldn't be too hard to get a function that gives you the correct "approximate" value of the function near the indeterminate point, if there is one. It's just a bunch of special cases that you have to check for every time you do an operation that might possibly result in a div/0 error, right? Go ahead. DO IT! I'll wait.

    21. Re:Infinity by Rasperin · · Score: 1

      Shouldn't it just be +-infinity? (Except maybe with the +- char)

      --
      WTF Slashdot, why do I have to login 50 times to post?
    22. Re:Infinity by Darinbob · · Score: 1

      No finite number is closer or farther from infinity.

    23. Re:Infinity by Anonymous Coward · · Score: 1

      When you have 0/0, you hit two "obvious" but contradictory rules in basic algebra:

      Rule one: anything multiplied by zero is zero
      Rule two: anything divided by itself is one

      Mathematicians don't know which rule has precedence for 0/0, so there's no way a dumb machine can figure it out, which is why most programing languages just throw an exception if zero is the denominator.

      You left one out

      Rule Zero: divide by zero is undefined.

      That's the definition. The implication of the definition is that divide by zero is not allowed. Arguing precedence rules is just bad middle/grade school math.

    24. Re:Infinity by Anonymous Coward · · Score: 0

      Mathematicians do in fact understand that 0/0 is the exception to which rule two does not apply. Therefore there is no conflict. The reason most languages throw an error (and any language which doesn't do so is flawed) is because any non-zero value divided by zero is infinity and no system, real or imaginary, is capable of performing arithmetic on infinity because the answer will always be infinity. Therefore, division by zero cannot be allowed.

    25. Re:Infinity by Dunbal · · Score: 1

      You learn arithmetic long before you learn algebra, and a very basic rule of arithmetic is thou shalt never divide by zero because the result is undefined.

      --
      Seven puppies were harmed during the making of this post.
    26. Re:Infinity by Anonymous Coward · · Score: 0

      L'Hopital's Rule applies to a limit function. Which is NOT the same as the division operation.

    27. Re:Infinity by Quirkz · · Score: 1

      Just throw an absolute value operator around it, and you're set.

    28. Re:Infinity by ThePhilips · · Score: 2, Informative

      Asking what is X divided by zero is no different than asking what is Y plus red, or what is Z times pineapple.

      Actually these do make more sense.

      Ah, you naive physicists. Your attempts at trying to attach the math to reality always make me smile. And your believe that the human words mean the same thing in math - that's just hilarious.

      Because, it is just math. It's human invention and we can do whatever we like with it.

      But to the point: division by zero is not illegal - it is simply not defined.

      The usual mathematical workaround is to simply define another operation - "zivition" or whatever you like - which is just like division, but in case of X/0, it has value of X or 1 or 0 or whatever you like. Or one can even go step further and define the zivition as ternary operation: ziv(X, Y, Z) = { div(X,Y), Y!=0; Z, Y==0 }

      --
      All hope abandon ye who enter here.
    29. Re:Infinity by AmiMoJo · · Score: 2

      This. If the OP is tired of checking for this condition, they are doing it wrong. It's not hard to write code where there is simply no possibly of a division by zero happening.

      Even when handling external input you need to validate it in almost every case, so adding a simple !=0 test is trivial and a minor part of the bigger problem.

      --
      const int one = 65536; (Silvermoon, Texture.cs)
      SJW, n: "Someone I don't like, and by the way I'm a fuckwit" - AC
    30. Re:Infinity by Dunbal · · Score: 1

      Except a graph of the tangent function.

      --
      Seven puppies were harmed during the making of this post.
    31. Re: Infinity by Anonymous Coward · · Score: 0, Funny

      0/0 should be 1

    32. Re:Infinity by ArchieBunker · · Score: 1

      Take a number, say 5. Divide that into zero pieces. Division did not happen so you still have 5.

      --
      Only the State obtains its revenue by coercion. - Murray Rothbard
    33. Re:Infinity by gnasher719 · · Score: 1

      In many situations, you can use L'Hopital's Rule [wikipedia.org] to resolve 0/0.

      No, you can't. At least any mathematician will look at you with disgust if you claim that. You can use it sometimes to find the limit of f (x) / g (x), if the limit of f (x) and g (x) both exist and are equal to 0. That's something entirely different.

    34. Re:Infinity by Moof123 · · Score: 1

      Yes, they do. It is called L'hopital's rule. It is one of my favorite rules out there from Calculus.

      In short it states the for 0/0 or ininfity/infinity the result is equal to the derivitive of the number over the derivitive of the denominator. Still get 0/0? L'hopital it again.

      So something that acts like x/x near zero comes out as 1/1=1 (oversimplification), or if it acts like x/x at infinity is is 1/1=1.

      Look it up, it is a wonderful little tool in your mathematical quiver.

    35. Re:Infinity by ShanghaiBill · · Score: 2

      That's something entirely different.

      No, it isn't different. If you are about to calculate x/y, and both x and y are zero, then you may be able to look at where x and y came from. If both of them were calculated from differentiable functions, then L'Hopital's Rule may help you evaluate the ratio.

    36. Re:Infinity by Anonymous Coward · · Score: 0

      Mathematicians don't know which rule has precedence for 0/0

      In many situations, you can use L'Hopital's Rule to resolve 0/0. But a properly written program should never get in a situation of dividing by zero, and this is one of the dumbest "Ask Slashdot" questions in a while. Masking the interrupt makes about as much sense as driving blindfolded so you don't see the people you are running over.

      L'Hopital's Rule applies when the "limit" is 0/0 and you are trying to find the value of the limit. It doesn't work in a general, what-does-zero-divided-by-zero equal sense.

    37. Re:Infinity by Anonymous Coward · · Score: 0

      You sir are not a mathematician. A freshman in college taking Calculus would know La'Hoptials rule:

      or would know that the second rule is:

      Rule Two: anything divided by itself is one, except zero, which is indeterminate.

      It is indeterminate for a reason: That reason is left as an exercise:
      This is one of the dumbest "Ask Slashdot" questions in a while.

    38. Re:Infinity by onepoint · · Score: 2

      While I will respect the idea the you think this is the dumbest question in a while, It's does show what people are feeling and being frustrated by. And what I have found great about Slashdot is some of the more creative reply's. I am looking forward to this.

      Personally, I think, clean code with check's and filters makes for better programs, but today's behavior seems to indicate that product needs to be out the door ASAP or you are out the door ASAP. so sloppy code consistently comes forth.

      --
      if you see me, smile and say hello.
    39. Re:Infinity by Wycliffe · · Score: 2

      I think infinity makes a bit more sense than zero. And max is the closest thing to infinity.

      I think the biggest problem is that depending on the application, you might want different things to happen.
      I find in my code, that I tend to want one of 4 mutually exclusive things to happen:
      1) If denominator is zero, die.
      2) If denominator is zero, set denominator to 1 and continue.
      3) If denominator is zero, set denominator to 0.0001 (or some other similiar small number) and continue.
      4) If denominator is zero, set final result of x/0 to zero.

      Honestly, in my experience #4 (which is what the original poster suggested everyone should want) is rarely
      what I want. I almost always want one of the first 3. I do occasionally want #4 but setting the final result
      to zero just happens to not be the use cases that I personally run into the most.

    40. Re:Infinity by vux984 · · Score: 5, Informative

      When you have 0/0, you hit two "obvious" but contradictory rules in basic algebra:

      Rule one: anything multiplied by zero is zero
      Rule two: anything divided by itself is one

      Ugh no, just no.
      "Rule one: anything multiplied by zero is zero"

      Yes, this is called, amongst other things, the zero property of multiplication. However 0/0 is not a multiplication and the rule is not relevant, and there is no conflict.

      Secondly your "rule two" is not actually rule of algebra. There is no rule x/x = 1.

      There is an identity rule for division: anything divided by one is itself (x/1 = x) but there is no rule that says x/x = 1

      You can derive "rule two" from the identity rule for multiplication x*1 = x --> x/x = 1

      However, that transformation always stipulates that x 0 because division by zero is undefined.

      Mathematicians have no issue determine which rule has precedence, because neither rule applies to 0/0.
      There is no conflict. Division by zero is specifically "undefined".

      Consider the equation; x/x.

      http://www.wolframalpha.com/in...

      The graph of the function is a horizontal line at y=1, with a discontinuity at 0. (if x=0, x/x=0/0) So 0/0 should be 1 right? Because everywhere else on the graph x/x = 1??

      http://www.wolframalpha.com/in...

      Now consider the equation 2x/x.

      http://www.wolframalpha.com/in...

      As x approaches 0 (lim x->0) from either the left or right the limit of the equation is 2. A graph of the function is horizontal line at y=2, with a discontinuity at 0. But every where else 2x/x = 2. So shouldn't 2(0)/0 = 0/0 = 2? So 0/0 should be 2 right?

      http://www.wolframalpha.com/in...

      Neither. Its not defined.

      Now consider the equation 1/x.

      http://www.wolframalpha.com/in...

      As x approaches 0 from the left it goes to negative infinity. As x approaches 0 from the right it goes to positive infinity. This graph doesn't even suggest a value for 0/0? Is it + infinity? Or - infinity?

      I can write a function that makes 0/0 look like it should be anything I want.
      0/0 is undefined. It doesn't violate any rules of algebra. It's a rule of algebra that division by 0 is undefined.

    41. Re:Infinity by Anonymous Coward · · Score: 0

      Your talking about the limit as x approaches zero. While this might sound like a way to determine the value at 0, it isn't. 1 / 0 is not both positive and negative infinity, it is just simply undefined. The function is discontinuous at 0.

    42. Re:Infinity by CaptainJeff · · Score: 1

      Here's where the problem is with that.
      Rule two: anything divided by itself is one
      Zero is NOT anything/something. It is the absence of anything.

    43. Re:Infinity by UnknownSoldier · · Score: 1

      Interesting list:

      0 * 1/z -> 0
      z / z --> 1

      The way it was explained to me was that it one analyzes division from the positive side towards zero, and division from the negative side towards zero you end up with this ...

      0/+0 is +Infinity
      0/-0 is -Infinity

      Since 0/0 is BOTH +Infinity AND -Infinity you end up with TWO values. Division is only closed when it produces a single number. The answer is undefined because we don't know WHICH infinity to pick.

      Mathematics hasn't evolved to multi-value constants.

    44. Re: Infinity by Anonymous Coward · · Score: 1

      L'Hopital has been mentioned many times in this thread. It does NOT resolve what 0/0 evaluates to. It resolved the LIMIT of a function as the terms approach zero. There's a difference.

    45. Re:Infinity by Chris+Mattern · · Score: 1

      Yes. It. Is. Different. f(x)/g(x) is undefined if f(x) and g(x) are both zero, and pretending it can ever be anything else is going to get you in a lot of hot water very fast. Now, then L'Hopital's Rule can help you find the limit as a approaches x of f(a)/g(a), but that is something different, and you have to be aware it's different.

    46. Re:Infinity by Anonymous Coward · · Score: 0

      I'm tired of hipsters pretending to be geeks, failing miserably, and then declaring jihad when called out. Somebody burst the tech bubble and wake us all up in 2007 please.

    47. Re:Infinity by AK+Marc · · Score: 1

      Mathematicians don't know which rule has precedence for 0/0,

      So all those times I worked out x/y where x and y both equal zero, for "as x approaches zero" weren't math. Funny, I think they were in my Differential Equations class.

      0/0 is undefined, but f(y)/f(x) where f(x)=0 isn't necessarily undefined.

    48. Re:Infinity by Archangel+Michael · · Score: 1

      I actually recall someone bemoaning that it is undefined, and thus causing confusion. The proposal, was to create a definition, a symobol/word, to describe a result that is x/0, and leave it at that. Because it does have meaning, we just haven't quite figured out how to wrap it up nice and neat.

      MY example is (1+(x/0))*2 is what? Does the fact that x/0 mean that it is not solvable? We have other terms for other numbers that seem impossible. SQRT(-1)

      --
      Agent K: A *person* is smart. People are dumb, stupid, panicky animals, and you know it.
    49. Re:Infinity by Cederic · · Score: 1

      I prefer the default option

      0) If denominator is zero, provide abusive error messages to the caller for not checking their inputs.

    50. Re:Infinity by Anonymous Coward · · Score: 0

      Ah, you naive mathematicians. Your attempts at trying to attach the metaphysics to math always make me smile. And your believe that the human words mean the same thing in philosophy - that's just hilarious.

      Because, it is just philosophy. It's human invention and we can do whatever we like with it. Asparagus ergo sum.

    51. Re:Infinity by Aighearach · · Score: 1

      Asking what is X divided by zero is no different than asking what is Y plus red, or what is Z times pineapple.

      We had five bucks, and we decided to divide it up. After we were done dividing, the money was all gone. That is dividing by zero. It was divided into zero pieces. The inputs are the number of pieces you end up with, and the original value. The size of each piece is the output. So given that you know there are zero pieces in the end, you know that they have zero size, because of algebra.

      This is true for almost any example involving money. Programmers who primarily deal with integers and money units find it natural to have anything that doesn't make sense to default to zero. If there was no result, and the units are money, it is accurate to say the result is zero dollars.

      The problem is, this doesn't work well for people doing scientific programming, where they expect IEEE standard results, regardless of how much extra error checking this creates. And regardless of the fact that way over 99% of the time where divide by zero is possible, the sanity checks simply detect the zero, and assign the result of zero to some variable without doing the division. Still, they consider this good.

      So in the end the answer is to use high level languages, and use money objects with sensible defaults instead of floats and ints for money values.

    52. Re:Infinity by khallow · · Score: 1

      Your attempts at trying to attach the math to reality always make me smile. And your believe that the human words mean the same thing in math - that's just hilarious.

      When a mathematical pattern occurs, be it in reality or in language, then the consequences of that pattern occur whether or not we choose to recognize it.

    53. Re:Infinity by eulernet · · Score: 2

      adding a simple !=0 test is trivial and a minor part of the bigger problem.

      Wrong !
      Of course, !=0 is fine when you deal with integers.
      But when you deal with floating point values, !=0 does not work.
      This is because there are rounding errors, the zero that is displayed can be stored internally as 10^-9, and rounded to 0 because the printing function uses 8 decimals.

      You have to use:
      fabs(value) > delta
      where delta corresponds to the rounding error.
      If you work with single precision, you can probably use delta=10^-6
      For double-precision, you need to verify the accumulated rounding errors.

    54. Re:Infinity by TechyImmigrant · · Score: 1

      Yup.

      Graph y=0/x as x -> 0 from both sides. It's a straight line (y=0) heading for (0,0).
      Graph y=x/x as x -> 0 from both sides. It's a straight (y=1) line heading for (0,1).

      At x=0, it could be either of those answers, or anything else. No one answer is correct.
       

      --
      I should use this sig to advertise my book ISBN-13 : 978-1501515132.
    55. Re:Infinity by ranton · · Score: 3

      We had five bucks, and we decided to divide it up. After we were done dividing, the money was all gone. That is dividing by zero. It was divided into zero pieces.

      Dividing something into zero pieces is not the same as dividing by zero. If you have no money left after dividing five bucks to five people, then the next attempt at dividing would be 0 / 5, not 0 / 0.

      Programmers who primarily deal with integers and money units find it natural to have anything that doesn't make sense to default to zero.

      Plenty of lazy programmers or those forced into using frameworks developed by other lazy programmers may be used to this. Perhaps even programmers forced to use primitive languages with no other options are used to it. But anyone else who knows what they are doing do not do this. This is similar to all of those developers who use NULL as if it means 0. Just because a lot of people do it doesn't make it any less idiotic.

      So in the end the answer is to use high level languages, and use money objects with sensible defaults instead of floats and ints for money values.

      Even low level languages have the capability of handling money correctly. It just requires more effort by the programmer, just like anything else done in a low level language. Considering all high level languages eventually have their code compiled down to the lowest level language understood by the CPU, low level languages are certainly capable of any calculation that a high level language is.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    56. Re:Infinity by TechyImmigrant · · Score: 2

      That's why I never use floating point. It's a mess. It's impossible to achieve a uniform random distribution of floats. The space isn't uniform.
      Fixed point is nice, as long as you have an idea of how big your numbers will be.

      --
      I should use this sig to advertise my book ISBN-13 : 978-1501515132.
    57. Re:Infinity by ranton · · Score: 3, Insightful

      Let me rewrite that as:

      Rule 1: 0*X (where X = 1/0)
      Rule 2: X/X (where X = 0)

      I've had this argument often with APL fans who don't get that as obvious as 0/0 = 1 may sound, it's not mathematically sound.

      If your code ever has the expression X / X and X is capable of being 0, you have a bug in your algorithm. It really is as simple as that.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    58. Re:Infinity by TechyImmigrant · · Score: 1

      Yes. It. Is. Different. f(x)/g(x) is undefined if f(x) and g(x) are both zero, and pretending it can ever be anything else is going to get you in a lot of hot water very fast. Now, then L'Hopital's Rule can help you find the limit as a approaches x of f(a)/g(a), but that is something different, and you have to be aware it's different.

      It works in the physical world. Don't be so dismissive.

      --
      I should use this sig to advertise my book ISBN-13 : 978-1501515132.
    59. Re:Infinity by Anonymous Coward · · Score: 0

      Also nothing stops OP from writing a class or method(s) to handle division so that X/0 actually returns zero.

      I feel the problem is OP's, not OP+Everyone Else's.

    60. Re:Infinity by TechyImmigrant · · Score: 1

      Interesting list:

      0 * 1/z -> 0
      z / z --> 1

      The way it was explained to me was that it one analyzes division from the positive side towards zero, and division from the negative side towards zero you end up with this ...

      0/+0 is +Infinity
      0/-0 is -Infinity

      Since 0/0 is BOTH +Infinity AND -Infinity you end up with TWO values. Division is only closed when it produces a single number. The answer is undefined because we don't know WHICH infinity to pick.

      Mathematics hasn't evolved to multi-value constants.

      If you're using normal numbers. Any self respecting field is closed over its operators, including division.

      --
      I should use this sig to advertise my book ISBN-13 : 978-1501515132.
    61. Re:Infinity by Samantha+Wright · · Score: 1

      By "it" I meant the limit; I don't think my phrasing was inaccurate.

      --
      Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
    62. Re:Infinity by Verdatum · · Score: 1

      ;) fair enough.

    63. Re:Infinity by complete+loony · · Score: 1

      And in C not just the result, but the behaviour is undefined. If you divide by zero the compiler, runtime libraries and the CPU can do whatever they like. They could ignore you, crash, format your hard drive or kill your pet.

      For speed reasons, this is a good thing. If it looks like you might run into undefined behaviour, the compiler can assume that the inputs to the program won't trigger that behaviour. This allows all kinds of optimisations to be performed, from dead code elimination, to hoisting invariant code out of loops.

      At least other high level languages define precisely what a divide by zero should do. That way you run into platform or compiler specific heisenbugs far less frequently.

      --
      09F91102 no, 455FE104 nope, F190A1E8 uh-uh, 7A5F8A09 that's not it, C87294CE no. Ah! 452F6E403CDF10714E41DFAA257D313F.
    64. Re:Infinity by Beck_Neard · · Score: 1

      Those are made-up 'rules'. And it has nothing to do with 'mathematicians not knowing which rule has precedence.'

      The IEEE floating-point standard defines x/0 = Inf when x is nonzero and NaN otherwise. That's a good choice in my opinion.

      Integer division by zero is often deliberately designed to throw an error, because doing it is an indication that there is something obscenely wrong with your code. The thing that went wrong in your code probably happened way before you even got to the error. Be thankful that your cpu lets you know your code is horribly broken instead of returning a gibberish response (which 0 or any other number would be - a gibberish response). There's nothing stopping you from implementing an integer arithmetic standard that incorporates Inf, but to do this in a consistent way would probably break every single application that uses integer arithmetic, including fundamental stuff like random number generators and cryptography code.

      --
      A fool and his hard drive are soon parted.
    65. Re:Infinity by mysidia · · Score: 2

      We have other terms for other numbers that seem impossible. SQRT(-1)

      Sqrt(-1) is also undefined in the real numbers. It is defined only in the complex numbers.

      In the complex number system, (Sqrt(-1), 0) is just equal to (0,1)

      The complex number system is a closed field, which you won't find in a system that allows division by 0..... the complex numbers are essential fundamental to Physics and also provide the fundamental connection between Geometry and Algebra, and it's useful in particular for solving the roots of polynomials and finding coefficients, in particular the solutions of cubic equations.

      I await anxiously to see someone propose a number system where assigning a definition to X/0 makes any sense and actually has any value.

    66. Re:Infinity by Anonymous Coward · · Score: 0

      Agree. Did early mathematicians give up when considering 1 - 2? Did they say the result was undefined? No! They invented negative numbers.

    67. Re:Infinity by fnj · · Score: 1

      Secondly your "rule two" is not actually rule of algebra. There is no rule x/x = 1.

      With the domain defined as finite real numbers, I don't believe you, and furthermore I can't believe you would state such an absurdity. It is the fundamental identity.

      Multiply both sides by x:
      x/x = 1
      x = 1 x
      x = x

      If that ain't the most fundamental rule of algebra, I don't know what is.

    68. Re:Infinity by mysidia · · Score: 1

      Rule two: anything divided by itself is one

      These rules actually have nothing to do with the formal mathematical definitions of multiplication or division; they are someone's informal observations about the results of applying formal rules, and commonly used as instructional aids and logistical shortcuts to help students.

      Rule one can be derived from how multiplication is defined it's not "anything" multiplied by zero though, that is a simplification, so beginners don't have to worry about number theory, number systems, functions and domains and ranges; a technically correct variant of Rule one would be "Any member of the domain of real numbers multiplied by zero is zero.".

      The same also holds for complex numbers and integers.

      Do keep in mind the rules is not Any object multiplied by zero is zero. If you have an X, such that X is not a member of the set of numbers, then 0*X is not guaranteed to be zero.

      Rule two: anything divided by itself is one

      Rule two should be any real number over which division is defined divided by itself is one. In other words:
      f(X,Y) = X/Y;

      If (X,Y) are elements of the set of real numbers,
      Then f(X,Y)=1 if and only if (X = Y and Y not equal to 0).

      Or... If X = Y, then Either: f(X,Y)=1 or a value f(X,Y) does not exist in the real numbers.

    69. Re:Infinity by Rockoon · · Score: 1

      I think infinity makes a bit more sense than zero. And max is the closest thing to infinity.

      IEEE floating point has both positive and negative infinity, as well as positive and negative zero. IEEE also took the trouble to define division by these signed zeros as resulting in one of these signed infinities.

      So strictly speaking, computers already can and do return a default value for division by zero. Its just not the value that this guy wants.

      --
      "His name was James Damore."
    70. Re:Infinity by HuguesT · · Score: 2

      clearly lim x->0 x^2/x = 0

    71. Re:Infinity by Anonymous Coward · · Score: 0

      To the submitter's credit, 0 would be the average of both possible values.

      Yeah, I'm confused as the rest of the commentators as to why they'd let this basic programming question on the front page.

    72. Re:Infinity by martas · · Score: 0

      Well, yes and no. It is often convenient to use the convention that 0/0=0, e.g., when computing local averages one does not have to go to the trouble to specify "if there are no points in the neighborhood, define the average as zero", so one uses this shorthand. Same goes for things like 0*log(0). But this is nothing more than a temporary local modification to notation.

    73. Re:Infinity by the+phantom · · Score: 1

      In the one-point compactification of the real (or complex) numbers, it makes sense to assign the value infinity to x/0. This is both meaningful and has value (particularly in complex analysis). That being said, the original question is asinine. It betrays a fundamental misunderstanding of both mathematics and programming.

    74. Re:Infinity by AthanasiusKircher · · Score: 1

      Secondly your "rule two" is not actually rule of algebra. There is no rule x/x = 1.

      There is an identity rule for division: anything divided by one is itself (x/1 = x) but there is no rule that says x/x = 1

      You can derive "rule two" from the identity rule for multiplication x*1 = x --> x/x = 1

      Huh? You've just stated two formulations that mean the same exact thing. Yes, when you set up axioms for a system of arithmetic, you often might derive things the first way, but there's no reason you couldn't first prove "x/x = 1" as a basic theorem instead and derive your "identity rule for division" from that. You generally wouldn't need either of these as axioms -- they both can be derived once you define division in terms of multiplication, i.e., something like "Given a and b with a != 0, there is exactly one x such that a*x=b. This x is denoted by b/a." (This theorem can be proven from more basic axioms involving identity elements and an axiom allowing the existence of a multiplicative inverse.)

      Once you've defined division, then you can go onto prove that a/1 = a or a/a = 1 or whatever. Neither of these statements is more basic than the other, since they both follow directly from the definition of division and the definition of the multiplicative identity element 1.

      In fact, usually a statement like a/a = 1 would be slightly more basic, since a^-1 can be defined as the reciprocal or multiplicative inverse once the theorem of division is proven. Thus a/a = a * a^-1 = 1, according to the definition of division and by the axiom asserting the existence of a multiplicative inverse (which usually states something like: "For every real number x != 0, there is a real number y such that x*y =1"). Your "identity rule for division" can then be derived from that.

      However, that transformation always stipulates that x 0 because division by zero is undefined.

      No -- that "transformation" doesn't "stipulate" anything. Division by zero is barred in the act of defining division -- because when you try to do the proof for my theorem above ("Given a and b with a != 0, there is exactly one x such that a*x=b. This x is denoted by b/a.") you'll find that x is NOT unique for situations where a is 0, which is the reason for its exclusion in the theorem.

      Which is what you go on to show with your various examples. But you don't need to show them, and you don't need to say that division by zero is "undefined" -- rather, when you try to DERIVE a reasonable definition for division from prior axioms, there's no consistent way of choosing a unique result for a division by zero. Therefore, it is generally left undefined, as in my example theorem.

      Mathematicians have no issue determine which rule has precedence, because neither rule applies to 0/0. There is no conflict. Division by zero is specifically "undefined".

      Yes.

    75. Re:Infinity by MrL0G1C · · Score: 1

      Perhaps the reason we can't work it out is because we are artificial intelligences in a big computer simulation.

      Don't think too hard, you might crash teh sim!

      --
      Waterfox - a Firefox fork with legacy extension support, security updates and better privacy by default.
    76. Re: Infinity by Anonymous Coward · · Score: 0

      The problem is that you can prove that, but you can't prove that 0 div 0 is a specific value because it's not.

      There's a relatively large number of things that are undefined because they don't settle on a specific value. The limit of sin (x) as x approaches infinity is a good example. We can't just define it to be 1 because it's convenient at times.

    77. Re:Infinity by martas · · Score: 1

      There is an identity rule for division: anything divided by one is itself (x/1 = x) but there is no rule that says x/x = 1 You can derive "rule two" from the identity rule for multiplication x*1 = x --> x/x = 1

      Uh, that's not true. You can't derive existence of multiplicative inverse from existence of multiplicative unity, you have to assume existence of multiplicative inverse. For example, the ring of integers contains multiplicative unity, but does not contain multiplicative inverse. And there is no identity rule for division, there is just an identity rule for multiplication -- i.e., 1 is defined as the element that has x*1=x for all x.

    78. Re:Infinity by blue+trane · · Score: 1

      500 comments about how silly this question is? Maybe you've been trolled? Or maybe there's more to the question than you would like to admit?

    79. Re:Infinity by Anonymous Coward · · Score: 0

      So we need to define a new value which is both positive and negative infinity, clearly.

    80. Re:Infinity by the+phantom · · Score: 1

      Well, I think that it could be argued that the *fundamental* theorem of algebra is more fundamental (that's the rule that, when vastly oversimplified, states that polynomials have roots). That being said, the identity that you propose is, as pointed out by the GP, an identity derived from properties of multiplication. It is not really all that fundamental, and one of the hypotheses of the identity is that x is not zero.

    81. Re:Infinity by turbidostato · · Score: 3, Informative

      "In many situations, you can use L'Hopital's Rule to resolve 0/0.
      No, you can't."

      Yes you can.

      "At least any mathematician will look at you with disgust if you claim that"

      No mathematician will look at you with disgust by claiming that. Armchair wannabes, on the other hand...

      Because any mathematician will know this is about programing, an algorithm context and, therefore, *in many situations* 0/0 will be a context case of f(x)/g(x) as both functions' independent variable approach zero, so a limit, that is, the very scenario L'Hopital's rule applies to.

      There will be, of course, many other situations where this will not be the case, a thing both the mathematician and the parent poster are also well aware of.

    82. Re:Infinity by Anonymous Coward · · Score: 0

      Nope. NaN. We have NaN. The answer is NaN. 0/0? NaN. 1/0? Also NaN. Just fucking use NaN.

    83. Re:Infinity by Anonymous Coward · · Score: 0

      Doubles have +inf and -inf so you could make X/0 equal to one of those, provided X is not itself 0. Then you could make X = NaN, which is a valid double as well. It is still a fairly bad idea to do it in general though. Floating point math is already fairly bad as far as accuracy goes, without letting an infinity go into the mix and blow everything out of the water. Divide by zero really needs handled somewhat more intelligently. Don't believe floating point is bad? Use a Float32 for t=0 and then use it for t=0.1 then subtract the two and look at the difference. After that compare t=3600 and t=3600.1 and subtract them. The result is different. More bits get tied up in the magnitude and you get greater and greater errors. Float64's help of course and allow things to keep going smoothly for awhile, but they are not lossless. The only true lossless math is done in integer data types, and then only addition, subtraction, multiplication, modulus, and of course logic operations. Division can go either way, but you generally assume it is lossy, unless of course your willing to keep all your math as fractions that you continually try to reduce, which would not be fun.

       

    84. Re:Infinity by CauseBy · · Score: 1

      I argue for 1. The reason 1 makes sense is because 1 is the limit from both sides. If you graph y=x/x, you get a straight line at y=1, with a hole at x=0. But the lim x -> 0 from the left and right are both 1.

    85. Re:Infinity by vux984 · · Score: 1

      Huh? You've just stated two formulations that mean the same exact thing.

      No. They are NOT quite the exact same thing. The identy x*1 = x is defined for all x in the set of Real numbers. The 2nd form is not.

      x*1 = x is defined for x=0
      x/x = 1 is not defined for x=0

      Just as a graph of y=1, is not quite the same as a graph of y = x/x. The latter has a discontinuity at 0, the former is continuous.

    86. Re:Infinity by Anonymous Coward · · Score: 0

      I think infinity makes a bit more sense than zero. And max is the closest thing to infinity.

      42 is closer

    87. Re:Infinity by khallow · · Score: 0

      Same goes for things like 0*log(0).

      L'Hopital's rule allows one to evaluate x*log(x) as real x approaches zero from the positive side. The limit turns out to be zero even with slight modification of each term, (eg, replacing the product with (ax)*log(bx) still leaves the limit as zero). That's very different from the 0/0 case which evaluates to 1 for x/x, but which can evaluate to other numbers easily with the same slight modification ( (ax)/(bx) goes to a/b).

    88. Re: Infinity by Anonymous Coward · · Score: 0

      Wow. Someone with an opinion that actually hints at something a computer system might do as a rule ... With the result being undefined, perhaps the operation should simply return the enumerator?

    89. Re:Infinity by martas · · Score: 0

      L'Hopital's rule allows one to evaluate x*log(x) as real x approaches zero from the positive side. The limit turns out to be zero even with slight modification of each term, (eg, replacing the product with (ax)*log(bx) still leaves the limit as zero).

      Without context, that's an arbitrary choice of a limit, albeit an aesthetically pleasing one. Generally speaking there is no reason why 0log0=0 makes any more sense than 0/0=0. Either might make sense to use as convention for a specific problem, which again is a temporary local modification to notation.

    90. Re:Infinity by khallow · · Score: 0

      Without context

      Such as things going to zero at roughly the same rate (eg, a linear multiple)?

    91. Re: Infinity by Z00L00K · · Score: 0

      0/0 should be 0.

      In all other cases it's either positive infinity or negative infinity.

      --
      If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
    92. Re:Infinity by Anonymous Coward · · Score: 0

      If your code ever has the expression X / X and X is capable of being 0, you have a bug in your algorithm. It really is as simple as that.

      Yes, I was thinking the exact same thing! If you are regularly getting divide by zero errors, this should be taken as a big warning that there is something seriously wrong with your code. Rather than furtively sweep the error under the rug, it would be much better to investigate where your code is going wrong. This, among other things, is what separates crappy code from not too obviously bad code. Frankly, this should be basic Computer Science 101 type stuff.

    93. Re:Infinity by Wycliffe · · Score: 1

      I prefer the default option

      0) If denominator is zero, provide abusive error messages to the caller for not checking their inputs.

      Yeah, that was the first option and you definitely should check your inputs but many
      times when you check your inputs and the denominator actually is zero then your
      program needs to decide how to continue. In the most common case I run into, setting
      the denominator to something small like 0.0001 and letting the program continue is
      an acceptable solution.

    94. Re:Infinity by Anonymous Coward · · Score: 0

      Zero is NOT anything/something. It is the absence of anything.

      Captain Philosopher, you are not.

    95. Re:Infinity by martas · · Score: 1

      That context does not exist in the expression "0*log0". You invent it. Can you tell me what it is inherently about 0*log0 that tells you it makes sense to imagine it as the limit of x*log(x), instead of, for example, as the limit of 0*sum_{n=1}^N (-1^n)/n? Setting aside the fact that it happens to give the same answer, as that is immaterial.

    96. Re:Infinity by Dog-Cow · · Score: 1

      That is simply false. There are an infinite number of algorithms that might contain the (sub)expression X/X for which zero is a valid value of X. To assume it's a programming error is sheer unmitigated stupidity that I might expect from a mathematician that has never written a real program in his life.

    97. Re:Infinity by vux984 · · Score: 1

      You can't derive existence of multiplicative inverse from existence of multiplicative unity, you have to assume existence of multiplicative inverse.

      Right. I'm not deriving that.

      And there is no identity rule for division

      Formally speaking, your right. But for a precalculus audience x/1 = x is taught as a 'property of division'. I perhaps misspoke calling it a 'rule'.

    98. Re:Infinity by martas · · Score: 1

      Overindulging precalculus audiences is how you end up with stupid shit like "why don't we define 0/0=0"... Talking about rings and fields might only confuse them, but at least they'll know that there's stuff they don't know (with apologies to Donald Rumsfeld).

    99. Re:Infinity by Anonymous Coward · · Score: 0

      I think the AC was clearly talking about indeterminate forms, where the statement was not entirely baseless.

    100. Re:Infinity by Anonymous Coward · · Score: 0

      ...which would be completely arbitrary and have no physical or mathematical significance beyond merely throwing up a consistently arbitrary and meaningless value.

    101. Re:Infinity by Anonymous Coward · · Score: 0

      When you have 0/0, you hit two "obvious" but contradictory rules in basic algebra:

      Rule one: anything multiplied by zero is zero
      Rule two: anything divided by itself is one

      Mathematicians don't know which rule has precedence for 0/0, so there's no way a dumb machine can figure it out, which is why most programing languages just throw an exception if zero is the denominator.

      Wow. Just wow.

      No. Very no.

      Saying that mathematicians don't know the precedence of an operation is simply a big misunderstanding of math. Mathematicians define precedences, they don't discover them. It's impossible for them not to know.

      The reason for the undefined nature of 0/0 is much more interesting.

      IEEE 754 includes infinity, +0 and -0. They're not artifacts or errors, as IEEE 754 turns to limit algebra to minimize numeric errors. They are, however, quite unintuitive.

      In floating point, 0 is not necessarily 0. That's where underflow occurs. When underflows results in intermediate computations, IEEE 754 at least retains the signum of the results by mimicking limit algebra, and making a difference between -0 (approaches 0 from the negative side) and +0 (approaches zero from the positive side).

      This allows intermediate computations to avoid sign flipping when flush-to-zero occurs, and thus a higher chance of getting a more accurate result.

      In this limit algebra, if N is any strictly positive number (N > 0), N / +0 is treated as lim x -> 0+ of N / x, which is infinity. That is, a very large number. IEEE 754 allows representing infinity, both positive and negative. Similarly, -N / +0 is thus negative infinity (that is, a very negative number). And here comes the usefulness of -0, for -N / -0 is positive infinity (because it's lim x -> 0- of -N / x, where x is always negative, so the result is known to be positive).

      However, in limit algebra 0 / 0, that is, lim x,y -> 0,0 x/y, does not have a defined value. It's not that they don't know, it's that there is no convergence to a single value, different approaches either converge to different values or simply oscillate infinitely. So there is no number that is the limit, and so in floating point, 0/0 is not a number (NaN), or a division by zero exception/interrupt, depending on the operation mode (which IEEE 754 defines, as a tool to guard against numerical error).

      So, a default exist, in the form of floating point operation modes, but many languages don't expose them. Instead of 0 as a result, which makes no sense, IEEE 754 gives the option of NaN. You can easily convert NaN to 0, and thus you can easily implement your desired operation mode if that's convenient for you (which it seldom is).

    102. Re:Infinity by Jane+Q.+Public · · Score: 5, Insightful

      That is simply false. There are an infinite number of algorithms that might contain the (sub)expression X/X for which zero is a valid value of X.

      No, there aren't. There are zero algorithms were 0/0 is "valid". 0/0 is simply not a number. You don't get to make up mathematics as you go and make it a number, no matter how convenient you might find that. If your algorithm treats it as a valid number, your algorithm is wrong.

      In fact, most compilers and interpreters will barf if you try to feed them that. (Division by zero error, or "NaN", depending.) You'd have to do a bit of trickery to make it work at all.

      To assume it's a programming error is sheer unmitigated stupidity that I might expect from a mathematician that has never written a real program in his life.

      It isn't an "assumption". It *IS* a programming error. The fact that the result of division by zero is undefined is a fact of life, not just some made-up mathematical construct. You can prove that to yourself with a framing square and a couple of sticks, if you don't believe me.

      An algorithm that assumes pi is equal to 3.0 is no more stupid than assuming 0/0 is valid.

    103. Re:Infinity by Anonymous Coward · · Score: 0

      Or one can even go step further and define the zivition as ternary operation: ziv(X, Y, Z) = { div(X,Y), Y!=0; Z, Y==0 }

      I like this last zivision. I think I may adopt it.

    104. Re:Infinity by Samantha+Wright · · Score: 1

      It's been done. The results were crap.

      --
      Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
    105. Re:Infinity by Anonymous Coward · · Score: 0

      A rule of thumb for numerical methods is that if your real-valued calculation requires a check for division by zero, it should be rewritten to make the check unnecessary, because the answer is also likely to be wrong due to numerical instability in a neighborhood of zero. For example, the quadratic formula: (-b +/- sqrt(b^2 - 4ac))/(2a) yields 0/0 when a = 0, but the best solution to that isn't to check for a=0 but to use the modified version of the formula method recommended in https://en.wikipedia.org/?title=Loss_of_significance .

    106. Re:Infinity by cpm99352 · · Score: 1

      I believe this is slighly incorrect. In the very first chapter of many algebra/trig/calculus textbooks there's something to the effect that we study y = f(x), where there is only one solution for f(x). In other words, linear. As a kid I wondered why 1/0 was undefined. I only learned at the end of linear algebra, in college, when it came to inverse functions.

      We know that x * 0 = 0, for any value of x. However, if we take the inverse operation of multiplication (that is, division), there is an infinite number of solutions for x / 0. Since we're operating in a linear system where there's only one solution for y = f(x), having more than one solution is undefined.

      Clear as mud... This is why Feynman was a genius and I am not.

    107. Re:Infinity by Anonymous Coward · · Score: 0

      But to the point: division by zero is not illegal - it is simply not defined.

      This s so so wrong and I'm shocked, absolutely shocked, that it seems the whole of Slashdot doesn't know this.

      Divide by zero is clearly defined and that value is NAN. Do none of you read the standards??!???!!

    108. Re:Infinity by someone1234 · · Score: 1

      This is the reason you must know how did you approach 0/0 and usually you want to select a good "default" instead of bailing out with an exception or NaN.

      --
      Patents Drive Free Software as Hurricanes Drive Construction Industry
    109. Re:Infinity by Anonymous Coward · · Score: 0

      If you look at it asymptotically then it's also possibly +/- infinity depending on which side you're approaching from.

    110. Re:Infinity by Anonymous Coward · · Score: 0

      Not quite true, in DSP processing it's quite normal to ignore algebraic 'weirdness' like this in the interest of simply getting an answer for each input sample.

    111. Re: Infinity by Anonymous Coward · · Score: 0

      Please tell me how to test for a NaN with an 8 bit unsigned integer please, or what standard covers it.

    112. Re:Infinity by Anonymous Coward · · Score: 0

      I think you used the unicode character for x != 0

      This makes your otherwise excellent post a bit unclear.

      BTW, Thiere's something everyone around here is missing. Floating point 0 is not actuallly zero. It's actually a representation of any number from just below the smallest floating point number and zero.

      This means that the situation is actually worse than you represent. It's perfectly possible that the answer to 0/0 is undefined now, however if we switched frmo single to double accuracy floating point numbers the answer would be a clearly defined 8. In this situation the problem with the algorithm is not that it's badly defined. The problem is probably that it's completely failing to take into account error bars. However, if we do take into account error bars then returning an answer of "NaN" with error bars of "Infinity" may be much better than throwing an exception.

    113. Re:Infinity by Anonymous Coward · · Score: 0

      muaaahahahahaha muahahahahaha

      renormalization

      Have you considered that your puny "mathematics" may be a just a strict limit of the possibilities of quantum mechanics where such major problems things as the "halting problem" become merely trivially solvable by stastistical measurement. Quake with fear innocent mathemeticians.

    114. Re:Infinity by ArcherB · · Score: 1

      But a properly written program should never get in a situation of dividing by zero, and this is one of the dumbest "Ask Slashdot" questions in a while. Masking the interrupt makes about as much sense as driving blindfolded so you don't see the people you are running over.

      Let's say a business divides the profit among all employees who meet certain conditions, say, a sales quota. If the profit is $1000 and four employees met the condition, their bonus is $250 ($1000/4). Now, what happens if no employees meet the quota? Your formula ends up being $1000/0 and crashes.

      Yes, the programmer should have planned for this, but that is the point of the question. The programmer is tired of combing through thousands of lines of code looking for division to see if it's possible to get a divide by zero error, and then having to sanitize is divisor for every one.

      So, I respectfully disagree with your reasons calling this a stupid question. He's asking, "Is there a better way of doing this than method X?" and you're saying, "That's a stupid question because if you used method X, you wouldn't have to worry about finding a better way".

      --
      There is no "I disagree" mod for a reason. Flamebait, Troll, and Overrated are not substitutes.
    115. Re:Infinity by Anonymous Coward · · Score: 0

      The usual mathematical workaround is to simply define another operation - "zivition" or whatever you like - which is just like division, but in case of X/0, it has value of X or 1 or 0 or whatever you like. Or one can even go step further and define the zivition as ternary operation: ziv(X, Y, Z) = { div(X,Y), Y!=0; Z, Y==0 }

      20 years of programming and it is like he has never seen something like this? I don't think anything anybody says will be any help.

    116. Re:Infinity by Anonymous Coward · · Score: 0

      I think infinity makes a bit more sense than zero. And max is the closest thing to infinity.

      Not the closest. What about max+1?

    117. Re: Infinity by Anne+Thwacks · · Score: 1
      If I have a cake, and share it between zero people, how big is each person's slice?

      The answer is "that was a dumb question"

      You cannot share a cake between zero people. The cake may be still whole, but no person has a part of it of any size. Maybe they "could" have a part of almost any size, but that was not the question. (Maybe it should have been, but in that case, you have to provide for different max and min answers, and should have asked the question differently ).

      What is the answer to x/0? The answer is "you have got the question wrong!" - otherwise known as Error: divide by zero.

      How you report a divide by zero error, is of course somewhat context dependent. Silently ignoring it could well be the right approach if decoding VoIP. If controling a driverless truck - probably is not .

      Conclusion: Yes, after rather more than 70 years of computing, we actually have got this one right!

      --
      Sent from my ASR33 using ASCII
    118. Re:Infinity by Garridan · · Score: 1

      Mathematicians don't know which rule has precedence for 0/0,

      Ouch. +5, Informative indeed. <sigh>

      Mathematicians can argue for any value at all, not just zero or one. This means that neither of your "rules" could take precedence.

      Annnnd, on to your rules. Any number multiplied by zero is zero. Any nonzero number divided by itself is one. Of course, mathematicians are wont to generalize "number" to "field element". Go crack out on wikipedia: https://en.wikipedia.org/wiki/Field_(mathematics)

    119. Re: Infinity by Anonymous Coward · · Score: 0

      Wrong.

      If all you want is prevent div by zero exceptions, !=0 will do.

      No matter how small is the number, if it's not zero, it will works fine.

    120. Re: Infinity by Anonymous Coward · · Score: 0

      0/0 should be 0.

      Failed your math class, I see?

    121. Re:Infinity by ziggystarsky · · Score: 1

      I've written algorithms for machine learning, where I'm constantly doing things like multiplying 0 and infinity. And, depending on the situation it is totally clear what the correct result must be (either 0 or infinity).

      Take for example computation of the entropy of a deterministic Bernoulli distribution: You have 1 * ln 1 + 0 * ln 0. The correct result is 0.

      Mostly I am relying on the proper handling of infinity and NaN by the floating-point implementation; but sometimes I have to catch cases and correct the result by hand.

    122. Re:Infinity by Ihlosi · · Score: 1
      However 0/0 is not a multiplication

      It can be expanded to (0*1)/0 and then to 0*(1/0), since anything multiplied by one is itself.

    123. Re: Infinity by jovius · · Score: 1

      They also got fed up with writing endless strings of numbers on the sand, just to see result being washed away by the next tide, so they came up with the concept of infinity. Then, the surf was good!

    124. Re:Infinity by phantomfive · · Score: 1

      Shouldn't be too hard to get a function that gives you the correct "approximate" value of the function near the indeterminate point, if there is one. It's just a bunch of special cases that you have to check for every time you do an operation that might possibly result in a div/0 error, right? Go ahead. DO IT! I'll wait.

      lim x->0 1/X = ?

      Depends on if you are approaching from 1 or -1. So good luck to that guy!

      --
      "First they came for the slanderers and i said nothing."
    125. Re:Infinity by serviscope_minor · · Score: 2

      If your code ever has the expression X / X and X is capable of being 0, you have a bug in your algorithm. It really is as simple as that.

      Some old code I had years and years ago needed to calculate some bits and bobs from parameters in a data file. Because reasons many parameters were often missing. So I initialised everything to 0/0, then read in what existed in the data file and did the computations.

      If for calculations where all the parameters were defines, I got out a number, otherwise, I got NaN :)

      Worked beautifully.

      If you expect 0/0 = NaN, then it's not necessarily a bug. Like a simple matrix inversion routine written in the obvious way willemit a matrix of NaNs for a singular input. That seems reasonable and bug free to me even if it can hit 0/0 eventually for many inputs.

      --
      SJW n. One who posts facts.
    126. Re:Infinity by Anonymous Coward · · Score: 0

      Well lim x->0 x^2/x = 2 would indeed be interesting..

    127. Re:Infinity by ThePhilips · · Score: 1

      Divide by zero is clearly defined and that value is NAN.

      You have mixed up your sciences.

      Div by zero is not defined in the math, in the definition of the operation division.

      Div by zero is defined in the applied math.

      --
      All hope abandon ye who enter here.
    128. Re:Infinity by Immerman · · Score: 1

      >Shouldn't be too hard...

      Careful there, you're oversimplifying things and are going to confuse some poor sod. Not only do you have an infinite number of special cases to consider in which 0/0 has a function-specific definite value in the limit, you ALSO have an infinite number of discontinuous functions where 0/0 has a different value in the limit depending on whether you approach the limit from the positive or negative direction, and there is thus NO reasonable "approximation" to be offered.

      Also, you've got a math error:
      lim x->0 x^2/x = lim x->0 2x/1 = 0

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    129. Re:Infinity by rew · · Score: 1

      Suppose I have a variable A that ends up with the value Y*X. (Y might be a difficult calculation). Next I want to calculate B = A/X .

      This could happen for example when I'm doing physics calculations where the parameter X eventually cancels out.

      Anyway, this will end up with B = Y if you do the math and cancel out the X. However, if you let a computer follow through with the calculations, when X=0, you'll end up with a variable A with the value zero. And if you assign a value of "1" to 0/0 you'll silently get a wrong result when Y != 1.

      So: The computer should throw an error. There is no way a compiler can come up with a reasonable answer for the variable B.

      If you want it your way, you write B = X?A/X:1; If you want get rid of that expression everywhere in your code, you get a few choices. In C++ you could probably define a "myfloat" that overloads the division operator. Or you could make a "mydiv" function.

    130. Re:Infinity by serviscope_minor · · Score: 1

      I disagree.

      It's irritatingly easy to get a singular matrix buried deep in the middle of an ongoing calculation. Pretty much the only way of validating the input is to run the calculation and see if you get a singular matrix. Naturally, inverting a singular matrix gives 0/0 somewhere in the middle.

      Especially if you're working with large numbers of tiny matrices, such as in 3D Geometry like in computer vision, then the obvious, simple algorithms work well.

      In the ideal world you'd do allsorts of checks of condition numbers as you go along, but that's often really slow. If speed is of the essence, you just plough ahead and check for NaNs every so often: i.e. before the results of the sub calculation gets back into the main state.

      So I think NaN is a prefectly sendible default for 0/0.

      I guess that's different for integers, though, since they hace no space for representing 0/0. I think then some sort of recoverable exception is prefectly fine for 0/0 too.

      --
      SJW n. One who posts facts.
    131. Re:Infinity by Dynedain · · Score: 1

      When two different fields in different areas of your app accept 0 as a valid entry for legitimate use, its pretty dam easy to run into a divide by 0 condition or even a 0/0 condition.

      The point of the original post is that it could be pretty handy to have a sane predicable default result instead getting a runtime error or having to introduce conditional logic every single time you do divide by a variable or calculated value..

      --
      I'm out of my mind right now, but feel free to leave a message.....
    132. Re:Infinity by Immerman · · Score: 1

      >0/0 is undefined, but f(y)/f(x) where f(x)=0 isn't necessarily undefined.

      Yes, it really is. You *may* be able to determine a definite value for the *limit* of f(x)/g(x) where g(x)->0, and that may be a useful and meaningful value, depending on context. But that doesn't mean that there isn't a discontinuity in your function, only that the discontinuity *might* not be relevant in practical applications. And there are of course also plenty of functions where the limit as you approach the discontinuity is different depending on whether you approach it from the positive or negative direction.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    133. Re:Infinity by Dynedain · · Score: 1

      Unless of course 0 is a valid entry for the external input.

      Or if two external inputs negate each other somewhere in the process.

      $10 in credits, $10 in charges, net $0, what's the daily interest charge on that? Oh right, now I need to add a conditional before I do the calculation, lather, rinse, repeat all over your business logic tier.

      --
      I'm out of my mind right now, but feel free to leave a message.....
    134. Re:Infinity by TheRaven64 · · Score: 1

      It's not a problem for floating point, where division by zero is well defined (it's a NaN value). And division by almost-zero is not a problem in floating point either, though if you're going down one of the pipelines for dealing with subnormal values then be aware that it's likely 10-100 times slower than normal floating point calculations.

      --
      I am TheRaven on Soylent News
    135. Re:Infinity by Too+Much+Noise · · Score: 1

      The fact that the result of division by zero is undefined is a fact of life, not just some made-up mathematical construct.

      Looks like someone skipped Calculus 101.There are an infinite number of situations where division by zero is well defined, even 0/0. It all depends on how one approaches that point. To put it simply, if X/0 (with x finite or not) is a simple arithmetical calculation, you are right. If it's an algebraic one, more often than not the denominator and numerator are continuous functions and certain ways of sending one or both of them toward zero have well-defined limits. Sometimes those limits are all equal (think 1/x^2 for x -> 0, left and right limits are +Inf), sometimes not. In the first case division by zero is perfectly well defined if you compactify the real axis to include +-Inf. The same approach works (or not, if there's no well-defined limit) for expressions going to 0/0 - heck, it's how derivatives are calculated for differentiable functions, for one thing.

      The common mistake that code monkeys do, which makes them state things like your affirmation, is confusing operations done by the CPU (arithmetics) with operations done in code (which come from algebraic expressions). The above should make it clear that division by zero is undefined for the CPU, but not necessarily so for code (or mathematics). Now, how you handle it in code so as not to trip the CPU is the actual problem, but it does not make it wrong (duh!)

    136. Re:Infinity by Anonymous Coward · · Score: 0

      Where do infinate answers come for x/0?

    137. Re:Infinity by Chalnoth · · Score: 1

      That doesn't work either, because is the result +infinity or -infinity? In mathematics, this divide may be doable in some situations as a limit, but the limit as x -> 0 of 1/x is different depending upon whether it's approaching zero from the negative side or the positive side. And the computer has no notion of limits in this context, it makes no sense to resolve a number divided by zero to anything at all. And, of course, as others have mentioned there's also the problem with 0/0.

      There is simply no way to have a consistent arithmetic system while still allowing divide by zero, of any number. If you tried to actually implement this in general, and had a significant number of divides by zero, you'd quickly find that your results were becoming corrupted by the divides.

    138. Re:Infinity by Immerman · · Score: 3, Informative

      >Does the fact that x/0 mean that it is not solvable?

      Yes. Yes it does.

      In the most trivial simplification x/0 will be either positive or negative infinity, depending on the sign of x. If x=0 then we can't even say that much.

      It's not a matter of "we haven't figured out how to wrap it up nice and neat", it's "We've tried to wrap it up nice and neat, but determined that the behavior is *extremely* context-sensitive and provably CAN'T be wrapped up". If a function has a discontinuity in the form 0/0 then you can "creep up" on it, evaluating the function at smaller and smaller distances from the discontinuity, and depending on the *exact* details the function may approach negative infinity, positive infinity, 1, 2, -237.428, or *any* other value. Or it may not approach any value at all - some functions will have a different value depending on whether you're creeping up from the left or the right, and some will even begin oscillating wildly with a frequency approaching infinity as they approach the discontinuity, so that it's not possible to get *any* approximate answer.

      THAT is what is generally meant when a mathematician says an operation is undefined. Not that we don't understand it, but that we DO understand it, and no general answer is possible.

      It's a very different situation from Sqrt(-1), which had provably consistent behavior [ sqrt(-1)^2 = -1 ] but simply couldn't be represented on the standard number line, requiring expanding to a two-dimensional complex number system in order to represent its behavior.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    139. Re:Infinity by Anonymous Coward · · Score: 0

      "No, there aren't. There are zero algorithms were 0/0 is "valid"."

      So what value does the sinc function ( y = sin(x)/x ) have at x coordinate 0 ?
      Also, nature does not have a problem with this 'invalid' result of the mathematicians. It just uses 1 as a substitute.
      Also, when calculating you can assume in this case that the answer is 1 and it will work perfectly.

      So 0/0 is a number, it just is not 0 but can be 1.

    140. Re:Infinity by AK+Marc · · Score: 1

      I can't find an example where that's true. Graph x/x, and you get a solid line at 1 from -infinity to +infinity with a discontinuity at 0, by definition. It's only definition that makes that a required gap. If one were to fill in that gap with 1, no earth shaking problems would happen, and for most user requirements, 1 is much more accurate than "undefined".

    141. Re:Infinity by Anonymous Coward · · Score: 0

      which is why most programing languages just throw an exception if zero is the denominator

      Not just programming languages. CPUs aren't too happy with divisions by zero either.

    142. Re: Infinity by Anonymous Coward · · Score: 0

      If you have 0 apples, and you give them equally to 0 people. How many apples did everyone get?

    143. Re:Infinity by Vitriol+Angst · · Score: 1

      I think your math skills and clear understanding of the rules is awesome.

      However,... if I were programming an animation and it's following a path y= 2/x, I'm going to have a smooth motion along screen at position 2 until I get to Zero.

      So do we handle it as an error? Undefined of course means undefined but do I have my animated plane just blink "undefined" at a random location and then suddenly re-appear on the screen?

      In this case, I'd imagine that having the prior two locations and next (estimate) would be handy to determine what y is when x = 0.

      Or perhaps we have a built-in exception handler if x = 0 BEFORE we calculate when we have x in a division statement. For instance, if we have a point on the screen and try and follow the mouse, there are 4 points where one of our numbers reaches 0.

      Consider this script;
      this.rotation = Math.atan2((object.y - mouse.y), (object.x - mouse.x)) * 180 / Math.PI;
      These days -- that code will work. Likely because someone at Adobe built in a handler just for these cartesian dilemmas to figure out at which quadrant X and Y were pointing to.

      Does it make practical sense that if X = 0, then X = .0000001 will get you a reasonable facsimile of what should occur with X?

      That solves the need to test for "undefined" -- even though more programming environments might be robust with regard to divide by zero errors.

      --
      >>"ad space available -- low rates!!!"
    144. Re:Infinity by gnupun · · Score: 1

      If you haven't read the article linked within the blog, nullity is supposed the new number that results when you divide something by 0.

      It's been done. The results were crap.

      The guy who posted on this blog is wrong:

      1. That currently, dividing by zero on a computer causes problems because division by
      zero is undefined. But if computers adopted nullity, then division by zero errors could be gotten rid of, because they'll produce nullity. Except of course that modern floating point hardware already *does* have a NaN value, and it *doesn't help* with the kind of problem he's talking about!

      But we're not talking about floating-point hardware. Integer hardware still does not have a NaN, so the programmer has to add extra code to handle divide by zero.

    145. Re:Infinity by Anonymous Coward · · Score: 0

      To be fair, approximating PI to 3 is usually good enough for all practical purposes. It's really not in the same order of magnitude than dividing something by 0.

      Cheers,

      A programmer who does not have any floating-point support on his embedded system

    146. Re:Infinity by Vitriol+Angst · · Score: 1

      I think this is a RULE we want to follow, but in the real world, like all those "corporate guidelines" that come from Human Resources -- nobody can actually follow all of them and get their job done.

      I can think of a lot of situations where I HAVE TO GIVE an answer when a value becomes Zero and I'm dividing with it.

      Animation, bank accounts and artificial intelligence to name a few.
      Dude; "Like if I have no money, so I give all of that to you but you have zero dinero change, and you've got zero patience with that, well, like that's your problem man."
      AI; "Does not compute, divide by zero, shutting down."
      Dude; "I can always get free nachos at the robo drive-thru this way."

      --
      >>"ad space available -- low rates!!!"
    147. Re:Infinity by gweihir · · Score: 1

      Divide by zero is not possible in Mathematics. Get over it. As incompetent programmers can still attempt to do it, the machine rightfully tells them that they just requested something that cannot be computed.

      --
      Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
    148. Re:Infinity by AmiMoJo · · Score: 1

      If you were calculating the interest on $0, why would you need to divide by anything? If the interest is, say 3% you would just do $0 * 0.03, which is not even a division.

      --
      const int one = 65536; (Silvermoon, Texture.cs)
      SJW, n: "Someone I don't like, and by the way I'm a fuckwit" - AC
    149. Re:Infinity by ultranova · · Score: 1

      Mathematicians don't know which rule has precedence for 0/0, so there's no way a dumb machine can figure it out,

      Because it has no context. But the programmer does. So how about letting the programmer denote blocks of code, such as functions, with how they want "x/0" to be handled for x=0 and x=/= 0?

      Alternatively, expand the exception mechanism. Currently, exceptions are a pain because when an exception occurs, the original point of computation is lost. But if the exception handler got it, for example as a continuation, with the ability to provide the result for the failed instruction (that is, when an instruction fails it gets replaced by a call to the exception handler which can either throw the exception for "real" or simply return a result), it would allow for such scenarios to be painlessly handled, both for x/0 and all other scenarios.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    150. Re:Infinity by Anonymous Coward · · Score: 0

      Bullshit.

      lim x->0 x^2/x = lim x->0 x/1 = 0

    151. Re:Infinity by Vitriol+Angst · · Score: 1

      If your algorithm treats it as a valid number, your algorithm is wrong.

      I'm curious if your detractor here has written code.

      I don't think a mathematician has "SHEER" stupidity, it's the problem with people who are smart, who think everything within the subset of their domain is figured out.

      I imagine security experts have this problem with hackers; "But I read the entire manual and what you did is not possible."

      Hacker; "Well, that's like, our opinion man."

      Cyber Security; "You are an idiot. You have no command of the lexical jargon."

      Hacker; "Hey, wasn't Lexical the name of your first pet?"

      --
      >>"ad space available -- low rates!!!"
    152. Re:Infinity by Anonymous Coward · · Score: 0

      Why are the wrong such assholes about their wrongness?

      It's not "simply false". There are NO algorithms that contain the subexpression X/X for which zero is a valid value of X. NONE. ALL algorithms that need to cope with this case HAVE TO intervene and place the specific value of 0/0 that they want, because there is NO WAY for the compiler / CPU to predict what the algorithm happens to need in that case. 0/0 = 0 (since 0/n = 0), 0/0 = 1 (since n/n = 1), 0/0 = 2 (since 2n/n = 2 and 2*0 = 0), 0/0 = 3 (since 3n/n = 3 and 3*0 = 0), 0/0 = pi^e (since x*pi^e/x = pi^e, and pi^e*0 = 0), I mean I could go on ...

    153. Re:Infinity by Anonymous Coward · · Score: 0

      That's something entirely different

      If by "something entirely different" you mean "obviously what the poster was tacitly driving at", then ... yes ... although it's a curious piece of pedantry.

    154. Re:Infinity by Ihlosi · · Score: 1
      CPUs aren't too happy with divisions by zero either.

      Depends on your CPU. It may have a setting to make it just return zero when dividing by zero. Sometimes, that's less harmful than other options.

    155. Re:Infinity by darkHanzz · · Score: 1

      There's NaN (not-a-number) for that. works beatifully

    156. Re:Infinity by Hognoxious · · Score: 1

      Grammatically that doesn't make sense.

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    157. Re:Infinity by Immerman · · Score: 1

      How about x / x^2? Approaches -inf from the left, and +inf from the right. I'm afraid I can't think of an example that approaches different definite values offhand, but I remember solving far too many back when I was taking Calculus.

      And like I said, yes, if you have a single definite two-sided limit on a discontinuity, then for most practical applications you'll probably be fine using the limit as the actual value. Though there's always the risk that you got that nice well-defined limit due to, for example, two counteracting forces approaching infinity, or counterbalanced resonance responses - in which case your practical application will quite likely rip itself to pieces long before you hit the actual discontinuity in your apparently nice smooth function.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    158. Re:Infinity by Samantha+Wright · · Score: 1

      It was a big story on Slashdot years ago. A similar cascade of discussions resulted. Let's think for a moment.

      If you don't want to code to prevent a division by zero error in any situation where NaN isn't handled elegantly, you have an easy alternative, which is a try/catch structure. Adding NaN is basically just a magic error value, like -1 being returned on failure for C functions (example: failing to find a substring returns -1 as the index in many languages.) This practice is considered Generally Bad And Inadvisable by structured programming dogmatists, as it encodes control information inside of a content signal and potentially obfuscates the meaning of the program (and, in languages like Python, where negative indices have meaning, it can cause lots of subsequent problems.)

      To keep things consistent, I would argue that NaN doesn't have a place in modern high-level languages that subscribe to structured programming paradigms; a division by zero is an error that occurs when data is improperly initialized or collected, and letting errors like this (a) propagate by ruining subsequent expressions and (b) potentially get displayed to the user is the vice of a PHP programmer who would rather just be told his or her code works rather than know if it was actually doing what was intended.

      On the other side of things, I do actually agree with you and would propose that signed integer formats should reserve 0x8000000 (whatever the negative maximum value is, that one extra number you can't fit into the positive side anyway due to the asymmetry of two's complement) for NaN, because exception-handling invariably means unnecessary stack frame manipulation when used in C++, and programmers in low-level languages like the C family should have an alternative, just like they do with string search functions.

      --
      Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
    159. Re:Infinity by hazeii · · Score: 1

      Great example is the sinc function - sin(x)/x is continuous; sin(x)/x is 1 with x zero.

      --
      All your ghosts are just false positives.
    160. Re:Infinity by psmears · · Score: 1

      I've written algorithms for machine learning, where I'm constantly doing things like multiplying 0 and infinity. And, depending on the situation it is totally clear what the correct result must be (either 0 or infinity).

      But that is the key point - you're right that, in many situations, it makes sense to assign a particular value to 0/0 (and other pathological cases) - but the thing is that the value that needs to be chosen depends critically on the situation at hand. Sometimes 0/0 might need to be treated as 0, sometimes 1, sometimes 42, and sometimes it is indicative of an error. Only the person writing the program can know which value is appropriate for the circumstance, so they must express it explicitly in the program. If programming environments throw an exception in the case of 0/0, it indicates that the programmer has not considered this choice, and that there is therefore a bug; by contrast, choosing one particular value would make some small subset of implementations work, at the expense of making all the others (which needed different values, or an error) give the wrong answer without any indication of a problem.

    161. Re:Infinity by ultranova · · Score: 1

      It's positive infinity when descending on the positive numbers, but negative infinity when ascending from the negatives. No one value can represent both!

      Of course it can. A humble vector is an example of just that. It simply means that any calculation involving said value will similarly return a value representing multiple values.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    162. Re:Infinity by Anonymous Coward · · Score: 0

      like:

      lim x->0 x^2/x = 2

      How have you gotten upvoted to +4?

    163. Re:Infinity by inasity_rules · · Score: 1

      Lim as x->0 of X/X =??

      --
      I have determined that my sig is indeterminate.
    164. Re:Infinity by gnupun · · Score: 1

      you have an easy alternative, which is a try/catch structure.

      That's not easy, instead it's a nightmare. If you add try/catch near the point of division, you have to add these try-catch boilerplate code all over your code base. If you add the try-catch at a higher level (near your main()), that too causes headaches because now you have to restart and reinitialize the parts that got discarded after the exception was thrown.

      It is precisely to handle these types of problems that the IEEE 754 standard uses NaN or Infinity for div-by-zero (because divisions are extremely common in FP code). That is, it is better to generate and propagate the wrong result (NaN) than it is to filter inputs and other data that cause div-by-zero, or handle exceptions in try/catch.

      I do actually agree with you and would propose that signed integer formats should reserve 0x8000000

      Yes, the highest bit should be reserved for nullity/NaN. Any arithmetic operation on a nullity variable should result in a nullity. There won't be any drop in performance if the CPU supports it, but the range of integers will be halved (from 2 billion to 1 billion for int32 variables). But that's not a big deal in a world where 64 bit integers are common.

    165. Re:Infinity by Dog-Cow · · Score: 1

      Code which divides by zero is not "horribly" broken. At worst, it's simply missing a test and branch. It's perfectly legitimate to have code which is general which has an input for which zero is a valid value. As division by zero is not mathematically defined, it's simply up to the developer to assign a context-specific result. That's it. No need to go off about supposed horribleness.

    166. Re:Infinity by BlackPignouf · · Score: 1

      lim x->0 x^2/x = 2

      Let's pretend you didn't write it, okay?

    167. Re:Infinity by Anonymous Coward · · Score: 0

      If you know A, and you know X = 0, and you would like B = Y, then you have NO option other than to recompute Y, because you can of course NEVER know what value Y had.

      Y = 5;
      X = 0;
      A = Y*X = 0;
      B = X?A/X:1 = 1;
      B != Y
      It's not the compiler fucking up.
      You are promoting silently getting errors in your physics computations. Yeah... keep that shit out of the compiler

      I work as a postdoc in applied mechanics, writing physics simulation software all days. Every case where there is a possibility of division by zero requires specialized code to handle it. There is no and obviously can never be a general solution.

      The best you can do is what languages already do. NaN and in some languages, Inf.

    168. Re:Infinity by udippel · · Score: 1

      Some nice arguments.
      However, I'd unify the first two, because the first is the same as the second, and both are only instances of rx/x. Which is always r, except for x=0. So the lim is the same from both sides, 1/-, : r.
      The other alternative is the last one: 1/x. Here the function values from both sides are infinitely different.

      I agree with the 'most stupid question ever asked on Slashdot', because it is clear that x/x for x=0, or any division by 0 is simply a mathematical indefinite.

      No wonder we have so much of lousy software!

    169. Re:Infinity by BlackPignouf · · Score: 1

      You're both correct for X divided by zero. It's simply not defined.

      But GP was right for "Y plus red" and "Z times pineapple".
      Both are defined in a mathematical sense :
      * If Y is an integer, "Y+red" is defined in the free abelian group on the generator {1,red}.
      * My math is rusty, but "Z times pineapple" should be defined in a multi-variable polynomial ring.
      You don't need physics to define any of them. You can draw parallel to physical units, but you don't need to.

      Finally, you're free to think that math is a human invention. My personal feeling is that we discover math more than we invent it, but I guess we'll never know for sure.

    170. Re:Infinity by udippel · · Score: 1

      Almost, unknown soldier.
      Since there is no convergence for this function, it is undefined. Not only undefined with its sign, but also with its value. It can have any value, infinity, 0, pi, e, banana or apricot.

    171. Re:Infinity by udippel · · Score: 1

      You must be a mathematician.

      How do you divide your cake among 0 people: you don't divide. Contradiction in itself.
      Cannot be done. Over.

    172. Re:Infinity by Ihlosi · · Score: 1
      Code which divides by zero is not "horribly" broken.

      Depends on the code. If dividing by zero results in occasional audio glitches, it's not horribly broken. If dividing by zero results in the code occasionally killing people, it's horribly broken.

    173. Re: Infinity by Z00L00K · · Score: 1

      If the value is zero, then the result is zero regardless of what it's divided by, so in that case zero is a good result and in practical aplication better than a value of 1 or infinity. Especially since the value zero lacks sign - you can't do positive or negative infinity.

      Or as stated elsewhere - if you divide zero apples with zero - how many pieces do you have?

      --
      If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
    174. Re: Infinity by Z00L00K · · Score: 1

      From a practical perspective the result would be zero.

      --
      If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
    175. Re: Infinity by Anonymous Coward · · Score: 0

      I can argue that pi=3 might can be valid

    176. Re:Infinity by fgrieu · · Score: 1

      Nope. NaN. We have NaN. The answer is NaN. 0/0? NaN. 1/0? Also NaN. Just fucking use NaN.

      I wish I could moderate that one up! Where are those moderator points when you need them most?

    177. Re:Infinity by ThePhilips · · Score: 1

      Finally, you're free to think that math is a human invention. My personal feeling is that we discover math more than we invent it, [...]

      That is not uncommon opinion.

      But IMO the opinion is biased by the human perception.

      For example, some interesting areas of algebra are so weird and require such level of (let's call it) free thinking, that the normal human brains simply refuse to work with them. Or the brains simply fry after too much trying. The tales about mathematicians degenerating as human beings as they advance in the math, have unfortunately a lot of truth to them.

      [...] but I guess we'll never know for sure.

      My personal counter-argument to the opinion: show me a "1" in the nature. Because even a singular particle isn't really "one".

      And the question is much easier on normal people, compared to: show me a 0 in the nature? The very concept of the zero - of what it represents - is unnatural.

      --
      All hope abandon ye who enter here.
    178. Re: Infinity by RavenLrD20k · · Score: 2

      Your principle isn't 0/0. It's 0/1, which is 0. You have to exist in the equation to be able to process the division, so by default there is 1 person. If there were 0 people then a Schrödinger's Cat situation emerges. Quantum supposition states that if there is no one to observe that there are 0 apples...then there are infinite apples at the same time there are none. Therefore 0/0 is undefined, and in programming should always throw an exception that can be handled gracefully (ask user to verify inputs, etc). Defaulting 0/0 to 0 in programming is a very dumb idea as it will create more problems than it solves.

    179. Re:Infinity by Anonymous Coward · · Score: 0

      mathematicians known that there is no consistent number

      Perhaps mathematicians known that, but English scholars certainly do NOT known that.

    180. Re:Infinity by Gunstick · · Score: 1

      30 years ago, the Atari just got in my nerves by crashing programs through divide by zero. So I finally replaced the exception handler with a simple RTE.
      The problematic program did not crash anymore. And also had no misbehavior, so that was fine for me.
      The next program might behave differently :-)

      --
      Atari rules... ermm... ruled.
    181. Re:Infinity by Anonymous Coward · · Score: 0

      lim x->0 x^2/x = 2

      If you're using L'Hopital's Rule, then lim x->0 x^2/x = 2 = d(x^2)/dx / d(x)/dx, which is 2x/1. Evaluating this at x=0 leads to lim x->0 x^2/x = 0

    182. Re:Infinity by Anonymous Coward · · Score: 0

      Which is why random numbers use a 0.0= n = 1.0 range for floating point.

    183. Re:Infinity by Anonymous Coward · · Score: 0

      hmmm.. less than symbol stripped out...

      That is supposed to be the range 0.0 is less than or equal to n and n is less than or equal to 1.0.

    184. Re:Infinity by SkunkPussy · · Score: 1

      > When two different fields in different areas of your app accept 0 as a valid entry for legitimate use, its pretty dam easy to run into a divide by 0 condition or even a 0/0 condition.

      But why does the algorithm attempt to perform the operation of division with a divisor that can take the value of 0? Its not defined in mathematics.

      --
      SURELY NOT!!!!!
    185. Re:Infinity by PetiePooo · · Score: 1

      That is simply false. There are an infinite number of algorithms that might contain the (sub)expression X/X for which zero is a valid value of X. To assume it's a programming error is sheer unmitigated stupidity that I might expect from a mathematician that has never written a real program in his life.

      As someone with a degree in mathematics and a degree in computer science (with special academic honors, I might add), I strongly disagree. Fix your damn program to check for a dividend of zero, or at least trap the exception and handle it then. If NaN or any of the infinities are useful in your computation, do it outside the normal math libraries or choose a language that explicitly permits them.

      To assert that it's not a programming error is sheer unmitigated arrogance that I might expect from a code monkey who barely scraped by his high-school math courses, assuming you even attended any.

      And yes, I've made my living writing programs, many of which benefitted from my knowledge of higher mathematics.

    186. Re:Infinity by Ihlosi · · Score: 1
      Fix your damn program to check for a dividend of zero, or at least trap the exception and handle it then.

      If you have the CPU cycles for this, it is the better option. Depending on the application, you may not have this luxury (really low latency signal processing where trapping an exception will break the real-time behavior of the system).

    187. Re:Infinity by ranton · · Score: 1

      If your code ever has the expression X / X and X is capable of being 0, you have a bug in your algorithm.

      If you expect 0/0 = NaN, then it's not necessarily a bug.

      You are correct there. A more accurate statement on my part should have been:

      If your code ever has the expression X / X and X is capable of being 0, if your code does not treat this as an error and handle it properly then you have a bug in your algorithm.

      Treating 0/0 as NaN is an example of handling the error properly, considering you are no longer treating the result as a valid number.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    188. Re:Infinity by ranton · · Score: 1

      The point of the original post is that it could be pretty handy to have a sane predicable default result instead getting a runtime error or having to introduce conditional logic every single time you do divide by a variable or calculated value..

      We understand what the OP was asking for and why it would be handy. We are simply explaining why it is not possible. Not just why it is probably not possible, but why it is literally not possible.

      I would also love a programming language which always knew what I wanted it to do during runtime errors automatically; I simply don't see it happening before we figure out general artificial intelligence.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    189. Re:Infinity by ranton · · Score: 1

      Frankly, this should be basic Computer Science 101 type stuff.

      It is CS 101 stuff, which is why so many people are saying it isn't possible. What I don't understand is how many people are actually defending the OP and agreeing that they would want the same thing. I guess these are the same programmers who cannot pass the Fizzbuzz test.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    190. Re:Infinity by ceoyoyo · · Score: 1

      Surprisingly, mathematics is not built on the rules of thumb they teach kids in junior high. Zero divided by zero really doesn't make sense for quite deep reasons.

    191. Re:Infinity by Anonymous Coward · · Score: 0

      You have 10 apples. You distribute them equally among 0 baskets. How many apples are in each group? QED.

      Your original distribution pool is not even part of the question about the final quantity of items in the output distribution groups. Sure, you retain 10 apples, but they're not in a basket. And each of the 0 baskets has 0 apples in it. The count of a null set is always zero, never null. This is the fundamental disconnect between "pure mathematics" and this question.

    192. Re:Infinity by ranton · · Score: 1

      Looks like someone skipped Calculus 101.

      It looks like someone just relied on the power rule to get through Calculus 101, and never really understood how what limits are. You use a lot of the terminology someone who understands Calculus would use, but there is a strong disconnect in understanding if you think finding where a function is approaching before it becomes undefined is the same thing as defining an undefined value.

      You do not divide by zero in Calculus, you determine what value the function approaches as the denominator approaches zero.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    193. Re:Infinity by ceoyoyo · · Score: 1

      You seem to have that backwards. Dividing your five dollars by zero is like dividing it among zero people and suddenly, poof, it's gone!

    194. Re:Infinity by AK+Marc · · Score: 1

      And like I said, yes, if you have a single definite two-sided limit on a discontinuity, then for most practical applications you'll probably be fine using the limit as the actual value.

      I didn't take your previous post as agreement, though your follow up is explicit abou 100% agreement, even if also in an argumentative tone.

      I never said anything about equations that tend to infinity, split or otherwise. I limited my comments to equations that had continuous vanues on both sides of 0 with a discontinuity at 0 by definition. For the original question, if you capture a divide by zero error, for 100% of user cases (and yes, violating mathematical rules) if you evaluate the equation at 0.00001 and -0.00001 and the values are equal, presenting the answer for "0" as the limit as x approaches zero, you'll give the user the answer they want/need in 100% of cases (except for those trying to generate an error). What is wrong with presenting x/x as "1" at zero? When would that ever cause a problem in an application?

    195. Re: Infinity by Anonymous Coward · · Score: 0

      just like the gp said...Failed your math class, I see?

      i will try to dumb it down for you a little. not all 0's are the same size, some 0's are smaller than other 0's. when numbers start approaching either zero or infinity some strange things can happen and they can converge to entirely different numbers than you expect.

      so tell me, what is the value of this equation? i will point out that it is a very important one in math.
      as x aproaches 0 (1+x)^(1/x) should be 1 right? because 1^inf = 1 instead you will find it is something around 2.718281828459... it is a very important constant in calculus.

    196. Re:Infinity by ceoyoyo · · Score: 2

      The IEEE did. It's called nan, and it's what most math libraries that don't die will give you back if you divide by zero. No, you can't do anything with it because it's not a number.

    197. Re:Infinity by Anonymous Coward · · Score: 0

      High-school?

      Should have learned in elementary school: you can't divide by zero.

    198. Re:Infinity by ranton · · Score: 1

      So what value does the sinc function ( y = sin(x)/x ) have at x coordinate 0 ?

      It has no value. What you have here is a discontinuous function. The graph may appear continuous to the naked eye, but it is not. Just pretending that y = sin(0)/0 = 1 is not proper math.

      Also, nature does not have a problem with this 'invalid' result of the mathematicians. It just uses 1 as a substitute.

      Nature has no problem with this situation because no practical application of sin(x)/x could ever have x = 0. This is the difference between just computing functions and actually applying them.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    199. Re:Infinity by PetiePooo · · Score: 1

      Of course. Then do your check for zero before the division, if your latency requirements can handle it. If either option doesn't meet spec, then your specifications are where the "bug" is...

      I kinda assumed that if someone is looking for a CPU to assign a number when dividing by zero, he's not in a job where they're asking him to do low-latency signal processing. VisualBasic is probably a better fit for his career path.. ;)

    200. Re:Infinity by ranton · · Score: 1

      I can think of a lot of situations where I HAVE TO GIVE an answer when a value becomes Zero and I'm dividing with it.
      Animation, bank accounts and artificial intelligence to name a few.

      Any time you have a situation where you have to give an answer when a denominator becomes zero is an example of error handling. Just because you have found a specialized way to handle the error while continuing on with your algorithm does not mean the function actually had a value when it divided by zero.

      Treating 5/0 as NaN and having your algorithm either skip the value or treat it as zero when computing an average would be an example of handling the error. But it still was an error, although in your specific instance you have determined handling the error was better than fixing your algorithm (which may become needlessly more complicated in your situation).

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    201. Re:Infinity by ranton · · Score: 1

      To be fair, approximating PI to 3 is usually good enough for all practical purposes. It's really not in the same order of magnitude than dividing something by 0.

      Approximating PI = 3 is perfectly valid. But approximating PI = 3.0 is not.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    202. Re:Infinity by Ihlosi · · Score: 1
      Of course. Then do your check for zero before the division, if your latency requirements can handle it. If either option doesn't meet spec, then your specifications are where the "bug" is...

      Or maybe you have bursts of data coming in that needs to be processed in a timely manner (leaving no time for exeptions or even checks), followed by periods in which you can comb through the data packets and deal with cases of division by zero (e.g. if you know that the result is normally nonzero, any zeros showing up in your data indicate that these samples need to be handled separately).

      It's all a matter of your application.

    203. Re:Infinity by Anonymous Coward · · Score: 0

      Technically it is a rule of arithmetic that division by zero is undefined.

    204. Re:Infinity by Anonymous Coward · · Score: 0

      Continuity. Look it up.

    205. Re:Infinity by Anonymous Coward · · Score: 0

      I douse the cake in lighter fluid and set it on fire, now nobody has any god damn cake. HAPPY NOW!!!!! :)

    206. Re: Infinity by RavenLrD20k · · Score: 1

      if you divide zero apples with zero [people] - how many pieces do you have?

      As I stated elsewhere [paraphrased to give a bit more detail for a non-AC]:

      [This example] isn't 0/0. It's 0/1, which is 0. The person identified by you has to exist in the equation to be able to process the division, so by default there is 1 person. If there were 0 people then a Schrödinger's Cat situation emerges. Quantum superposition states that if there is no one to observe that there are 0 apples...then there are infinite apples at the same time there are none. To put it more simply, there would be 0 people to even care how many freaking apples there are to be divided. Therefore 0/0 is undefined, and in programming should always throw an exception that can be handled gracefully (ask user to verify inputs, etc). Defaulting 0/0 to 0 in programming is a very dumb idea as it will create more problems than it solves.

    207. Re: Infinity by RavenLrD20k · · Score: 1

      So, practically speaking, if there are zero people to care about how many apples there are... who's there to define that there's 0 apples available?

    208. Re: Infinity by Anonymous Coward · · Score: 0

      It's a stupid question and this is a stupid mistake to make. If you're not paying attention to inputs things like this happen.

      If nobody qualifies for the bonus then the code shouldn't even execute that calculation. The result is hardly the only problem that can happen if you don't sanitize and check the inputs.

    209. Re:Infinity by myowntrueself · · Score: 1

      When you have 0/0, you hit two "obvious" but contradictory rules in basic algebra:

      Rule one: anything multiplied by zero is zero
      Rule two: anything divided by itself is one

      Mathematicians don't know which rule has precedence for 0/0, so there's no way a dumb machine can figure it out, which is why most programing languages just throw an exception if zero is the denominator.

      If x/0 = some constant, whatever that constant might be whether infinity, zero, 8 or whatever, you get this:

      x/0 = c = y/0 therefore x = y for all numbers.

      So all numbers are equal and mathematics completely breaks down.

      --
      In the free world the media isn't government run; the government is media run.
    210. Re:Infinity by RuffMasterD · · Score: 1

      But if algebra is compatible with quantum mechanics (and Schrödinger's cat), shouldn't divide by zero be able to maintain both positive and negative infinity states simultaneously? Until you observe it, at which time the superposition collapses into a definite state.

      --
      Human Rights, Article 12: Freedom from Interference with Privacy, Family, Home and Correspondence
    211. Re: Infinity by Anonymous Coward · · Score: 0

      42. 'Cause 42 times the number of people equals the total number of apples. I'm serious.

    212. Re:Infinity by RavenLrD20k · · Score: 1

      In the most trivial simplification x/0 will be either positive or negative infinity, depending on the sign of x. If x=0 then we can't even say that much.

      Actually, in any possible case of x, the result is always both positive AND negative infinity...and it is also always neither. As I mentioned elsewhere, divide by zero is essentially quantum superposition at work. The denominator being zero means that there is no "observer" for the numerator to collapse into a definitive form...and therefore there is no possible way to define the entire equation. Undefined != infinity. Undefined == Undefinable.

    213. Re:Infinity by Daniel+Franklin · · Score: 1

      That's so wrong it's not funny. Read what the parent wrote. It is correct and you are entirely wrong.

    214. Re:Infinity by Samantha+Wright · · Score: 1

      Yes, exactly like how the number 1 is simultaneously true and false due to the ambiguous nature of your local pizzeria's ingredients, which may or may not include pepperoni.

      --
      Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
    215. Re: Infinity by Anonymous Coward · · Score: 0

      Actually, sin(x)/x *is* continuous at x=0 and is equal to 1. Using l'Hopitals law you get that for x->0 sin(x)/x = cos(x)/1 (i.e. the derivatives of sin(x), x) = 1

    216. Re:Infinity by Immerman · · Score: 1

      > What is wrong with presenting x/x as "1" at zero? When would that ever cause a problem in an application?

      Probably nothing, assuming you've got a special case within your evaluation function that checks for encountering the discontinuity and returns the limit. That doesn't mean your function has a value at that point, only that you can fake it in a consistent manner that, in most applications, will result in a graceful workaround of what, in most contexts, is an annoying mathematical anomaly. But as I said such discontinuities can also be indicative of extreme behavior in the components - if this were a piece of engineering design software for example, hiding the discontinuity might conceivably result in a design with unsuspected vulnerablities.

      Also, if you are getting such a well-behaved discontinuity, there's a good chance you could simply rearrange/simplify your equation so that the discontinuity is never encountered at all. E.g. algebraically x/x = 1, so why are you ever performing the division at all?

      I hope it's also obvious that that is not something that can be gracefully generalized - without knowing the surrounding function there's no way to estimate what the limit at 0/0 might be (lim x->0 7x/3x = 7/3), or even if it has a limit at all.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    217. Re:Infinity by Samantha+Wright · · Score: 1

      I wasn't thinking of the highest bit, just the highest value. As I'm guessing you already know, because of the nature of two's complement there's an asymmetry in positive and negative numbers (2^15 - 1 positive values, 2^15 negative values, and zero) resulting in one value that could easily be discarded; assigning this single value to an error would have an additional benefit of catching counter overflow. Certain older computers like UNIVACs actually used another system called one's complement, where the most significant bit was a negative sign, and numbers otherwise counted up from zero—this had the odd result of leaving a "negative zero" in the numbering system (which IEEE floating point numbers also have); this could also have been reassigned to NaN.

      Yes, I agree that try/catch blocks are annoying from the perspective of people writing elaborate flat code—but they do force the programmer to actually handle errors instead of letting them propagate. In certain contexts this is vitally important. A programming language that permits NaNs is essentially making the decision that the division's failure is Not A Problem by default, which is a key point of contention: are we developing for a safety-critical application where a failure to test properly could have dire consequences? What if someone forgets to check for NaN values in the speed control system in an automobile? Is that better or worse than the program aborting entirely? (Almost certainly worse, as it's more likely there would be management code for catching and fixing that!)

      So I would argue that, say, MATLAB or Lisp should support NaNs, but definitely not Ada, and I guess now I'm unsure about the C languages again.

      --
      Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
    218. Re:Infinity by rwa2 · · Score: 1

      Oh, yeah, I fucked up... I failed at simplifying an example where lim x->1 (x^2 - 1) / (x - 1) = 2

      At least I know what to do to get lots of followup comments now ;-)

    219. Re:Infinity by Samantha+Wright · · Score: 1

      A vector is... really not an applicable answer, as fun as vectors are! We're only working with one dimension here.

      --
      Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
    220. Re:Infinity by rwa2 · · Score: 1

      Thanks for reminding me about L'Hopital's Rule... I vaguely remembered that there was some way to do it using derivatives of the numerator and denominator, but forgot what to actually search for ;-D

      5 mod points to the AC

    221. Re:Infinity by RavenLrD20k · · Score: 1

      So...when you graph the equation 5/x, where X hits zero a line is drawn horizontally and vertically with arrows indicating infinity in all directions, with the two curves shooting off the page of it at the positive and negative points where x no longer equals zero? Funny...I always thought that the 0 lines are completely devoid of any marks, specifically to denote that there is no defined value, infinity or otherwise.

    222. Re:Infinity by Immerman · · Score: 1

      Ah, thought of one with a definite discontinuity: x/abs(x)
      lim x->0+ x/abs(x) = 1
      lim x->0- x/abs(x) = -1

      Now absolute values may not get used a lot in normal calculations, but you may get the same effect if, for example, you're using square roots and only considering the positive result, as is extremely common in computations since standard data types can't hold an ambiguous value:
      i.e. sqrt(x^2) = abs(x), rather than the mathematically correct +/-x

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    223. Re:Infinity by rwa2 · · Score: 1

      Oh, yeah, I fucked up... Good catch! I failed at simplifying an example where lim x->1 (x^2 - 1) / (x - 1) = 2
      from https://www.mathsisfun.com/cal...
      which ends up being a pretty innocuous-looking line with a "hole" at x=1 , y=2

      But yeah, that's exactly my point that all div by 0 operations might not be "approximated" as +/- infinity , but under certain not-uncommon circumstances, 1 or 2 or any number could be a possible "approximation" of something that would otherwise throw a div by 0 error. But it's much more trouble to code for those special cases than just bailing out. And that was the point I was trying to make to troll for some mod points :P

    224. Re:Infinity by Immerman · · Score: 1

      No, it's very context dependent. The usual way to deal with divide-by-zero and other discontinuities is to use the calculus limit operation, the "creeping up on it" I referred to. You can think of it as looking at a graph and, if the function behaves nicely except at that one point, taking the value that it looks like it should have if there weren't an infinitesimal gap present.

      (lim x->0 ... is read as "the limit as x approaches zero of...")

      lim x->0 1/x = does not exist (positive or negative infinity, depending on the direction you approach it from)
      lim x->0 1/x^2 = +inf (the same from either side)
      lim x->0 Ax/Bx = A/B
      lim x->0 sin(1/x)/x = does not exist (oscillates smoothly between positive and negative infinity with an infinite frequency)

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    225. Re:Infinity by AthanasiusKircher · · Score: 1

      No. They are NOT quite the exact same thing. The identy x*1 = x is defined for all x in the set of Real numbers. The 2nd form is not.

      Those aren't the two formulations you mentioned. You mentioned the identity "x/1 = x" as though it were a fundamental rule of arithmetic. It is not. It can be derived from your multiplicative identity after you define division. But so can "x/x = 1."

      Or, to explain a little more: going from x*1 = x to your version of x/1 = x requires that you actually define what x/y means in the first place. And to do that consistently, you already need to exclude the fact that y != 0. Once you've done that, you can show that x/1=x, but you can just as easily show that x/x=1.

      Your "division identity" depends on a consistent definition of what division is. Thus you can only state it once you've excluded division by zero. (Well, technically you could state it as another axiom or something rather than deriving it, but most mathematicians don't see the point in adding in excess unnecessary axioms... especially in this case, where you'd still have to come up with a consistent definition of division.)

    226. Re:Infinity by aaronb1138 · · Score: 1

      This is actually a problem caused exclusively by the logical incorrectness of 0th based numbering to which so many programmers incorrectly subscribe.

      The rule anything divided by itself is one does not apply because the concept of zero is that it is NOT in fact anything. It is the definition of nothing, of lacking substance.

      Each time I run into equipment or object enumeration which starts with the first object numbered as "0" I shake my head at the fact that some engineer or programmer has missed the point of natural numbers: to delineate quantities of discreet objects. There is no such thing as "port 0" on a switch or "disk 0" in a SAN array, but I see this logic all the time because it makes writing loops and such tidier in software. The first port is "port 1", that is it is 1 whole, discreet object of the kind "port".

      This is an area of abstract thinking which is disconnected from the physical world and thus not understanding the intrinsic relationships of physics and mathematics. Zero is a special number used for defining nothing, not something.

    227. Re:Infinity by Anonymous Coward · · Score: 0

      Asking what is X divided by zero is no different than asking what is Y plus red, or what is Z times pineapple.

      Even when an expression divides by zero at a particular point in its domain, there could be a well-defined limit. Eg lim(x->0) x^2/x = 0

    228. Re:Infinity by Anonymous Coward · · Score: 0

      Multiplication and division are associate, you fucking moron.

      0/0 = x == x * 0 = 0

      1 * 0 doesn't equal zero, therefore undefined.

      YOU FUCKING MORON.

      Appropriate CAPTCHA: severe

    229. Re:Infinity by AK+Marc · · Score: 1

      That's not a counter example. I didn't prove my point mathematically because the mathematicians are more lawyer than human. Math is about proofs, not reality.

      Your counter example has a gap from -1 to 1, same as there'd be for x/x^2, where the limit as you approach from opposite sides is not the same. If the limit is the same from both sides, and well-behaved on both sides, why is interpolation logically (not mathematically) incorrect?

      The mathematicians will argue that math is logical and math says no, which is an argument that math = logic so apply math, not logic, but not that there's a logical fault in the interpolation.

    230. Re:Infinity by cellocgw · · Score: 1

      Lim as x->0 of X/X =??

      Sorry,can't tell if you're asking a question or posing a rhetorical response.

      The answer is "1" . The limit is NOT the same as the value of the expression at 0. Calculus is loaded with examples of functions whose limit is not the same as the value at the stated point.

      --
      https://app.box.com/WitthoftResume Code: https://github.com/cellocgw
    231. Re:Infinity by Anonymous Coward · · Score: 0

      So can we just settle on 0/0 = -237.428 and call it a day?

      Next order of business,

      0.99999... = 1

    232. Re:Infinity by snowgirl · · Score: 1

      That is simply false. There are an infinite number of algorithms that might contain the (sub)expression X/X for which zero is a valid value of X. To assume it's a programming error is sheer unmitigated stupidity that I might expect from a mathematician that has never written a real program in his life.

      Dude... you perhaps haven't heard, but computers run entirely upon theoretical mathematics... I know, it's popular to say it's engineering, rather than mathematics, but it's mathematics. It's always been mathematics.

      --
      WARNING! This girl exceeds the MAXIMUM SAFE standards established by the FDA for BRATTINESS
    233. Re: Infinity by vilanye · · Score: 1

      0/0 is indeterminate.

      n/0, where n!=0 is undefined.

      Infinity is not a number, so it would never make sense when dividing rational numbers.

      Not too pile on, but you seem to have failed arithmetic class.

    234. Re:Infinity by snowgirl · · Score: 1

      More importantly is what happens when you graph it: the limit of 1/x as x approaches zero is discontiguous. It's positive infinity when descending on the positive numbers, but negative infinity when ascending from the negatives. No one value can represent both!

      Let's assume that the set of integers is Z_\inf. K? We can now define negative numbers as the 1's compliment of the number plus 1. 1 = 999...9998. then plus 1 = 999...9999. This plus 1 results in an infinite carry out, and the value 0. Awesome.

      Now, let's look at 1/0, we see that from the right it's approaching \inf from the bottom, while we see that from the left, it's approaching \inf from the top. Now, at 0, obviously these two will be coincident, because we're working in Z_\inf, that value is the same value. Namely, -\inf = \inf. But that doesn't make sense, only 0 can be it's own negative!

      But we've already known for a long time about Z_n where n is even, -(-128) in Z_256 is -128. -(-65536) in Z_2^16 = -65536. So, there's no trouble in making -\inf = \inf ...

      Basically, 1/0 grows so fast that it manages to wrap around the entire infinite series of numbers. Which is exactly what it does...

      --
      WARNING! This girl exceeds the MAXIMUM SAFE standards established by the FDA for BRATTINESS
    235. Re:Infinity by vilanye · · Score: 1

      x/0, where x!=0 is always undefined.

      Since infinity is not a number saying that x/0 is +/- infinity is nonsensical.

    236. Re:Infinity by UnknownSoldier · · Score: 1

      > but also with its value. It can have any value, infinity, 0, pi, e, banana or apricot.

      I don't see how. When you take the limits there are only 2 values reached: +inf, -inf.

    237. Re:Infinity by hrimhari · · Score: 1

      I'd like to understand why we can't do the same trick we do with sqrt(-1) on (1/0) and call it "zeplex". Example:

      1/0 = Ê' (some applicable symbol)

      A zeplex number is composed of a real part and a zereal part: a + bÊ'

      Then:
      Ê'/Ê' = 1
      0*Ê' = 0

      And so on.

      It can't be just the asymptotic nature, because it doesn't seem to hold complex from being a valid concept. I.e.: http://www.wolframalpha.com/in...

      --
      http://dilbert.com/2010-12-13
    238. Re:Infinity by oldestgeek · · Score: 1

      Infinity is undefined!

    239. Re:Infinity by Immerman · · Score: 1

      You seem to be discussing asymptotes, which have a bit more subtle meaning. An asymptote is a line that a function gets infinitely close to without ever touching. Essentially the further you follow the asymptote the more it resembles the graphed function, but they will never be quite the same. 5/x gets two lines because it has two asymptotes: a horizontal asymptote at y=0, since the function gets infinitely close to y=0, but never actually reaches it no matter how large x gets, and a vertical asymptote at x=0 since the function gets infinitely close to x=0, but never actually reaches it no matter how large y gets.

      Asymptotes don't themselves have anything to do with division by zero though - for example the well-behaved function x^2/(x^2+1) has a horizontal asymptote at y=1, since the function will get infinitely close to y=1 but never actually reach it, but it doesn't have a vertical asymptote since it's well-defined for all values of x.

      Asymptotes don't even have to be aligned to an axis - for example, rather than a horizontal asymptote, the function y=x + 1/x gets a diagonal asymptote at y=x: the function will never quite touch that line, but the further you get from x=0 the closer the two resemble each other.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    240. Re:Infinity by Immerman · · Score: 1

      It's not a number in the normal sense of the term, but using it as such is a simple and convenient shorthand for the far more complex and subtle mathematical concepts being expressed by the statement. In fact it's so radically simplified that even a layperson can kind of vaguely wrap their head around it, while you'll probably need a PhD in mathematics to really understand the underlying concepts.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    241. Re:Infinity by vux984 · · Score: 1

      You could define anything you like.

      1) Are you sure that wouldn't simply make the whole system inconsistent? ie Can we use 1/0 = E to prove 0 = 1 ?

      2) What would that actually give us that would be useful?

      Complex numbers are useful.

    242. Re:Infinity by Jane+Q.+Public · · Score: 1

      Looks like someone skipped Calculus 101.

      Looks like someone took Calculus 101 and didn't understand it.

    243. Re:Infinity by Anonymous Coward · · Score: 0

      You don't need to have a PhD in Mathematics to understand cardinality. Everything discussed here is literally elementary mathematics.

      There is no simplification where division of two integers becomes an infinite set(either countable or uncountable). Dumbing it down just makes the term infinite completely meaningless and undefinable when in fact, it has a very specific(and simple) definition.

      Frankly, if you need any of this dumbed-down you do not belong on slashdot.

    244. Re:Infinity by Too+Much+Noise · · Score: 1

      Thank you, if this is all you have to say in reply then I'll take it as a compliment. An argument would have been nice, for instance why exactly anyone attempting to calculate (exp(x)-1)/x at x=0 is, you know, wrong, but I wasn't holding my breath for it anyway - facts tend to be confusing wrt absolute statements. Well, if saying division by zero is 'wrong' floats your boat, more power to you. Feel free to declare irrational numbers wrong as well, since they cannot be represented using a finite-word binary CPU.

    245. Re:Infinity by vux984 · · Score: 1

      However,... if I were programming an animation and it's following a path y= 2/x, I'm going to have a smooth motion along screen at position 2 until I get to Zero.

      No. You aren't.

      http://www.wolframalpha.com/in...

      What do you think it should do at 0?

      Does it make practical sense that if X = 0, then X = .0000001 will get you a reasonable facsimile of what should occur with X?

      Certainly not here. And in general no. Dividing by "nearly zero" is generally just as bad as dividing by zero. If X is approaching zero division by x is approaching an infinity.

      No matter what data type you are using you are going to blow past its MIN/MAX; you are propagating error into the significant digits, etc. 10^80

      Unless you are literally trying to plot a hyperbola or something, odds are if you are dividing something large by 0.0000000001 you are probably doing something wrong somewhere.

      And there are countless other examples where its just nonsensical. Lets say you are doing a test and have a running tally of pass vs fail... and you haven't made any fails yet... so 5 pass, 0 fail... 5/0 is an error; so we'll just display 5/0.00000001 because that's a 'reasonable facsimile' right? :)

    246. Re:Infinity by Too+Much+Noise · · Score: 1

      It has no value. What you have here is a discontinuous function. The graph may appear continuous to the naked eye, but it is not. Just pretending that y = sin(0)/0 = 1 is not proper math.

      That's an amusing, if not too common mistake - sinc(x) is indeed continuous at zero, no eye required. Do a Taylor expansion on sin(x) and you'll see that sinc(x) = 1 + O(x^2), which in this particular case is a series that converges everywhere on the real axis, including at x=0 (check the convergence radius using the usual methods, if you need to). But what do I know, I must have, how did you put it, 'relied on the power rule to get through Calculus 101.' Well, at least I got through it.

    247. Re: Infinity by Anonymous Coward · · Score: 0

      Careful - you're head is disappearing up your arsehole...

    248. Re:Infinity by dakra137 · · Score: 1

      In APL, 0/0 is a null vector. In APL the "/" symbol is the dyadic select operator. The left side is a binary scalar or a binary array with the same shape as the right side. The result has the elements of the right side that had 1's on the left side, or in the case where the left side is a scalar, if it's a 1 you get everything from the right, or if it is a 0, you get a null vector.

      You might have been thinking of 0&#247;0. Where &#247; is the division operator U+00F7

    249. Re:Infinity by hrimhari · · Score: 1

      Ah right, so it's actually:

      1/0 = ÃS'
      0ÃS' = 1

      As for the utility, if there are situations where a plot or solve 1/x for every x is necessary, I imagine there would be situations where it should be workable even if [.'. x] includes 0 without the algorithm being deemed broken because there's no "if x != 0 then 1/x else ???" in it.

      --
      http://dilbert.com/2010-12-13
    250. Re:Infinity by Anonymous Coward · · Score: 0

      but it won't work, since, as an extension to real numbers, it would have to be consistent with real number and there it always ends up at the point where x/0 can be ANYTHING and therefore has to be nothing. i^2=-1, on the other hand, is something completely different. thing is, your approach of sqrt(-1) does not work since there are two values that suffice für x^2=-1 (i and -i), where i is only the simplest solution, not the only one. if you write down complex numbers with length and angle, there is an infinite number of solutions, but all of them can be represented by i or -i.

    251. Re:Infinity by coinreturn · · Score: 1

      Asking what is X divided by zero is no different than asking what is Y plus red, or what is Z times pineapple.

      I say focus on a proper mathematical answer for multiplying by blue first, and then apply it to the equally nonsensical divide by zero question.

      Everybody knows that Z times pineapple is the square root of unicorn - by definition.

    252. Re:Infinity by vux984 · · Score: 1

      As for the utility, if there are situations where a plot or solve 1/x for every x is necessary,

      Think about that for half a second. Your just substituting 1/0 for some "E" symbol. How is the plot going to plot "E" on an x,y plane?

      It'll still need special handling, and special data types. (you can't sqrt(-1) on a double; you have to use special complex classes everywhere for that to be allowed;

      I don't generally use complex numbers when writing algorithms that plot circles or parabolas, because I'm not usually interested in complex results. If I'm plotting a circle on an x,y screen; using y = +/- sqrt(r^2 - x^2)+h; I'm not interested in complex results; and I'm using doubles in the algorithm. So sqrt(-1) is still an error to workaround, not i. (And if I was using complex numbers, then I'd still have to test for i and discard it.

      So what have we gained with 'zeplex' numbers? Unless it's actually useful for some other aspect of mathematics.

    253. Re:Infinity by Shaitan · · Score: 1

      It's covered by logic. To divide by nothing is to not have divided. Therefore anything divided by 0 would be itself.

    254. Re:Infinity by Aighearach · · Score: 1

      You seem to have that backwards. Dividing your five dollars by zero is like dividing it among zero people and suddenly, poof, it's gone!

      Right. Exactly my point, except that I used "pieces" instead of "people." Which is to say, when you're dividing equally between n people, the unit isn't actually the people but the count of people. If you're dividing into labelled jars it is exactly the same, and the jars aren't the units either; the count of portions is. You don't divide by the people, you divide by the count of people. The other person claiming apples/oranges is making the same mistake. And the unit issues shouldn't even come up when the issue is divide-by-zero, which doesn't implicate units at all.

      It always cracks me up when people misunderstand me, presume I said something that doesn't make sense, and then correct me by paraphrasing what I actually said but presented as a contradiction.

      I guess it is no wonder that people can't map real human scenarios that rely on numbers to mathematics very well; they're already off by -2n most of the time. But you got the essential element; when you divide into zero pieces, it means you have zero pieces when you're done dividing. People will insist such behavior is "undefined," but actually it is defined; either as an error condition, an action that is not allowed (an exception) or as infinity. On a computer this is defined differently for floats (infinity) and ints (exception). The idea that it is undefined is simply ideology run amok, and repeated for decades by school teachers. We have multiple competing definitions right now, for different problem domains. The idea that we "can't" have a sensible default for non-academic situations is pretty silly. Luckily the solution is also easy; don't use numbers directly in code, use objects that represent the units and overload the math operators when using those units so that sensible defaults will present themselves. For example, money classes can return 0. Graphics classes can return 0. Physics-simulation-related classes can return infinity. Still, it would reduce the code complexity in most cases to have the computer defaulting to 0 and having it raise exceptions or return infinity for special academic math types.

      I think this shows it was perhaps mistaken of early computer scientists to treat computer numbers as if the job of the computer is purely mathematical. If early programmers had been logicians or philosophers instead of mathematicians, we'd probably have pragmatic real numbers for standard use, and special functions or types for academic math.

    255. Re:Infinity by SirSlud · · Score: 1

      This is a little like saying it would be handy if the compiler knew what you meant when you wrote code that attemtped to do soemthing for which there is no specifically well defined answer. While you may know what default you want, it's not going to the the right default for another programmer. Hell, usually it's not going to be the right default for some other place in your code where you're allowing your software to try and divide a value by zero.

      In theory, you could make a compiler that does something, but it's not a good idea because it would involve some set of programming being satisfied 'with the default' and many others now stuck with possible bugs because their software doesn't crash when it tries and does something mathematically undefined.

      --
      "Old man yells at systemd"
    256. Re: Infinity by tastyrerun · · Score: 1

      This thread is a good example of why I love /.

    257. Re:Infinity by Dynedain · · Score: 1

      What's good for a particular algorithm buried in the code base is not necessarily good for user input which may be used a hundred other ways.

      0 could be a perfectly valid user input or calculated result of multiple user inputs that could cause the algorithm to choke.

      Prefixing every math operation you put in your code base with a check for 0 if the input values are unknown can be tedious, especially in obtuse languages/platforms that don't support good modularity - hence the OPs question about a globally consistent behavior.

      --
      I'm out of my mind right now, but feel free to leave a message.....
    258. Re:Infinity by Dynedain · · Score: 1

      According to another poster elsewhere, some processors do exactly what the OP requested, and that it's doable today in machine code. Other posters have mentioned that using unsigned or floating point integer types allow this behavior in various languages.

      There's no reason why it couldn't be supported by a language, and it's absolutely not impossible.

      Everyone's argument about it being impossible comes from expressing things in languages where it's explicitly "undefined" or NaN, or otherwise illegal in that language. If it's a standard and predictable behavioral rule of a language, then it's definitely usable in that language.

      Weak types in PHP or JS are very analogous. Sure, lots of people make mistakes with them (and there's other faults that encourage those mistakes), and most problems stem from inconsistencies in the language APIs when converting types, but if you understand how types work in those two languages you can write surprisingly complex behaviors using very simple and concise expressions. Simplicity and terseness is very important in a scripted language.

      --
      I'm out of my mind right now, but feel free to leave a message.....
    259. Re:Infinity by Dynedain · · Score: 1

      This is a little like saying it would be handy if the compiler knew what you meant when you wrote code that attemtped to do soemthing for which there is no specifically well defined answer.

      If the compiler or language has a consistent, documented behavior for the scenario, then by definition there is a specifically well-defined answer.

      For certain knowledge domains and programming patterns, this would not be a hurdle but a benefit. Languages are full of these behavioral "flavors".

      --
      I'm out of my mind right now, but feel free to leave a message.....
    260. Re:Infinity by JustSomeProgrammer · · Score: 1

      Was fire involved in the splitting? I'm just not sure how you divided up money and had no money at the end. I mean maybe you miscounted and divided $5 to 6 people by giving each person a dollar and then there was no money left for you... but that's a math error not 5/0. You cannot divide something into pieces and have 0 left. You can always recollect the pieces and get back to the original $5. If the division resulted in nothing left then you used fire to destroy the $5. Which is X-X not X/0.

    261. Re:Infinity by v1 · · Score: 2

      NaN is actually pretty simple to deal with using computers. If you use 16 bits to store a signed integer, you have 65,536 units to use. One of them needs to be 0, so you have an imbalance. -32768 to +32767 is common. But you can just use -32768 to represent NaN instead, and keep things slightly more tidy when handing overflows and underflows.

      Then anytime NaN comes up at any point in the calculation or comparison, even when divided by or subtracted from itself, the result automatically equals NaN.

      Nice and simple. Now go watch Numberphile and lose your afternoon watching all his other videos.

      --
      I work for the Department of Redundancy Department.
    262. Re:Infinity by Immerman · · Score: 1

      Except that there's nothing in the concept of infinity that is specific to sets, so cardinality is not really relevant unless we're specifically discussing infinite sets. Which we're not. We're discussing the limit of a single value that increases without bound as an input condition approaches a critical value. I'm sure you could rephrase that in terms of set theory, but that doesn't imply a fundamental dependence.

      And frankly, if you've hung around Slashdot long you should realize that a rather large percentage of the community doesn't have a really firm grasp of much mathematics beyond basic arithmetic. That doesn't mean they're not interested in the concepts being discussed though, and nothing is gained by belittling either them or those who offer them simplified explanations.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    263. Re: Infinity by Anonymous Coward · · Score: 0

      Use floating point and refer to the IEEE 754. In what context would you do an integer division without the ability to check for zero or even define your functions to never produce a zero as a result?

    264. Re: Infinity by Anonymous Coward · · Score: 0

      "We had five bucks, and we decided to divide it up. After we were done dividing, the money was all gone. That is dividing by zero."
      Ouch, I think that's called subtraction. 5-5=0. Not trying to be a dick.

    265. Re:Infinity by Anonymous Coward · · Score: 0

      This is correct. First you cancel one of the x's. This is allowed since we aren't dividing by 0, since x never actually is 0. Then we're left with lim x->0 x which = 0.

    266. Re:Infinity by Samantha+Wright · · Score: 1

      You're just validating your own arbitrary decision to use that integer set. IEEE 754 defines positive and negative infinity separately. (However, if you look at the other comments below this one, you'll see that I argued for exactly this, reassigning the largest negative value to NaN in a signed integer format—but only for select situations.)

      --
      Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
    267. Re: Infinity by Anonymous Coward · · Score: 0

      Nah, from a practical perspective it would be 2 1/2. 42. 7.996.

    268. Re:Infinity by lucien86 · · Score: 1

      Actually I am interested in FTL physics and have solved both the div zero and the negative roots problems by looking at the details of permutation.

      The solution to negative roots is to add the idea of superposition of sign to the definition of numbers so that n^2 expresses as +n x -n = -m. This also gives the rule that all imaginary numbers summed equate to zero. (i = (1,-1)SP2, sum i = 0) Complex numbers look like asymmetric imaginaries ( (3,-1)SP2 = 1 + 2i) The method produces the result that light itself has an imaginary mass +n + -n = 0..

      The solution to /0 is that the division operation never adds to the result so the strict answer is always zero, and the numerator becomes the remainder. (n/0 = 0 = remainder n) Note also that in this system zero can be an imaginary number and the result of div 0 or tan 90 is an imaginary (0,0)SP2.

      The same system uses a rule called a 'scalar window' to allow limited computation with infinite numbers. By this rule essentially all finite numbers have an infinite component and visa versa most or all non-finites have a finite component.

      --
      Below the speed of light Special Relativity is one of the most accurate theories in physics - above the speed of light..
    269. Re:Infinity by MechaStreisand · · Score: 1

      There are an infinite number of algorithms that *anything*. You are demonstrating your own sheer unmitigated stupidity.

      --
      Disclaimer: IANAL. This post is, however, legal advice, and creates an attorney-client relationship.
    270. Re:Infinity by MechaStreisand · · Score: 1

      You are stupid. If a Taylor series has the same value as y = sin(x)/x everywhere but is defined at 0, then it is not the same function as sin(x)/x, because sin(x)/x is not defined at 0.

      --
      Disclaimer: IANAL. This post is, however, legal advice, and creates an attorney-client relationship.
    271. Re:Infinity by Hognoxious · · Score: 1

      Clearly the answer is context specific, so it should be handled on a case-by-case basis in the code.

      In your example, you'd divide it by one and give it to the manager.

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    272. Re:Infinity by Anonymous Coward · · Score: 0

      I believe the article has no idea what it's talking about.

    273. Re: Infinity by Anonymous Coward · · Score: 0

      What about.. if you have 2 apples, and you give them equally to 0 people. How many apples did everyone get?

    274. Re: Infinity by Anonymous Coward · · Score: 0

      That is easy though

      x = 0.9... = 9/10 + 9/100 ...
      10x = 9 + 9/10 + 9/100 ...
      9x = 10x - x = 9
      x = 1

    275. Re:Infinity by __aabppq7737 · · Score: 1

      every expression can have multiple results, contradictory rules kill both results.

    276. Re:Infinity by __aabppq7737 · · Score: 1
      (0^2)/(0^1)
      1*(0^2)/1*(0^1)
      1*(0^1)/1*(0^0)

      If 0^0 = 1, then 0/0 = 1

    277. Re:Infinity by __aabppq7737 · · Score: 1

      0 / 0 is the union of all real and non-real numbers

    278. Re: Infinity by Anonymous Coward · · Score: 0

      Good example but it does quite work. If you had 2 apples and divided them equally among 0.5 person you get 4. Wuuut?!

    279. Re:Infinity by ceoyoyo · · Score: 1

      You've misunderstood me. The problem is not that you divided five dollars into zero pieces/people/whatever, it's that you don't have anything left afterward. If you're dividing by zero with a remainder, setting the quotient to zero and the remainder to the numerator is reasonable. If you're not doing remainder division (i.e. the remainder is always zero), it is NOT reasonable to set the quotient to zero, because that makes things disappear.

      Dividing with a remainder: $5 -> 0 groups, I still have $5.

      Regular division: $5 -> 0 groups, I have zero. Where's the $5?

      Perhaps if people misunderstand you a lot you should consider the idea that you're not communicating very clearly.

    280. Re:Infinity by spitzak · · Score: 1

      I believe the article has no idea what it's talking about.

      That is a better explanation, I agree

    281. Re:Infinity by Vitriol+Angst · · Score: 1

      You are technically correct but IMHO practically wrong. I'm talking about "real use" such as in animation, graphing and financial.

      An equation that uses Divide by zero might go to "max limit" or to zero (in practical terms), based on preceding values. It will not suddenly say; "Sorry, the resultant value is indeterminable".

      Graphs pass the zero mark all the time without a "NAN".

      We just run to the limits of Math as an abstract concept but we do indeed KNOW that the value is either really big or really small -- we just lack the mathematical proof.

      Until then, a lot of us are going to have to use a handler for divide by zero -- but a lot of scripts and programs already allow for it.

      --
      >>"ad space available -- low rates!!!"
    282. Re:Infinity by Vitriol+Angst · · Score: 1

      The algorithm doesn't need "fixing" -- it works perfectly.

      Computers are constantly animating objects based on the position of the mouse -- there are 4 points crossing the cartesian axis (immediately right or left, up or down), and we USED to, add a small value to the Zero figure and test if it's in quadrant [1,1 ; 1,-1 ; -1,-1; -1, 1] -- now it's automatic in a lot of programming languages -- at least as far as animation goes.

      The problem I'm seeing here is people who know a lot of math theories, but aren't seeing that Divide by Zero comes up a lot in the real world and we deal with it -- it used to be with error handling, but now it might be with a min/max limiter and store the negative and positive. Or with a test of ranges above and below the value.

      I wanted some input if "this was correct" from programmers.

      --
      >>"ad space available -- low rates!!!"
    283. Re:Infinity by SuricouRaven · · Score: 1

      But you haven't divided the money. You have disappeared it - and a very angry auditor is coming to ask how you managed that.

    284. Re:Infinity by khallow · · Score: 1

      Actually, your proof has 0/0=0 since the last line evaluates to 0 given the condition that 0^0 = 1.

    285. Re:Infinity by Anonymous Coward · · Score: 0

      When you have 0/0, you hit two "obvious" but contradictory rules in basic algebra:

      Rule one: anything multiplied by zero is zero
      Rule two: anything divided by itself is one

      But divide by zero isn't covered by either of those two rules of algebra.

      Asking what is X divided by zero is no different than asking what is Y plus red, or what is Z times pineapple.

      I say focus on a proper mathematical answer for multiplying by blue first, and then apply it to the equally nonsensical divide by zero question.

      Mathematicians do, actually, (in response to Joeblog's previous post). Inasmuch as if A divided by B equals C, then it follows that A MUST be equal to B times C. If A is NOT 0, and B IS 0, there is NO value C can have that fulfills this requirement. Even if we arbitrarily decide C is infinity, zero times anything, including infinity, WOULD BE zero, if infinity were a real number. As I predict I'm going to mention again, infinity is the excluded upper end-point of the real number system.) Conversely, if A AND B are BOTH 0, ALL values of C fulfill it, but the logical truth-content of the expression is lost or destroyed. That is...

      Let A = B = 0. Let C = A / B. Then A = B * C for ALL POSSIBLE VALUES OF C. We all know the rule for addition (and consequently the rule for multiplication) for equations, that if D = E, then for all real F, D x F = E x F. HOWEVER, and here's where it gets sticky. This rule only applies to F NOT EQUAL TO 0. Here's why.

      If you multiply both sides of an equation by 0, the resulting statement, 0 = 0 is TRUE, whether the original statement was true or not.

      Consider this. 2 = 3. True? Multiply both sides by 0, and you get 0 = 0, a true statement. Multiplying by zero destroys the truth value, (logically TRUE OR FALSE) of a statement, which means the underlying rule, multiplying both sides of a TRUE statement of equality, or a true relation, (D = E) by zero voids the assertion that D x F = E x F, when F equals zero.

      Therefore, If C = A / B, that A must equal C * B DOES NOT HOLD when B = 0.

      Further, we could add that the basic rule that you can multiply both sides of, let's just call it an equation, (though it includes inequalities, provided you reverse the sense when multiplying by less than zero as appropriate,) only holds over REAL NUMBERS, or FINITE COMPLEX NUMBERS, in either case of which, positive and negative infinity are considered the EXCLUDED endpoints of the REAL, (and finite complex) number systems. So yeah, you really might as well be multiplying by blue, when you talk of division by zero.

      BTW, despite what you may ever have been told, it's NOT infinity. A / 0 is NOT INFINITE, even if A > 0. There's an intuitive way to look at this. Suppose you have a bag of marbles, and there are some small but nonzero quantity of marbles in the bag. How long will it take you to remove ALL the marbles from the bag if you remove them 0 at a time? It's not forever. It's NEVER. As in you will not only NEVER remove ALL the marbles, even given limitless time, you will NEVER remove even ONE of the marbles. If you removed ONE marble every (arbitrary unit of time,) it's true that the LIMIT as the length of time increases without bound, (or goes to infinity,) the amount of time required to remove a finite number of marbles also increases without bound, (or towards infinity,) but it can never REACH infinity, just as you can never have a finite interval of INFINITE length. It's preposterous on its face.

      So the correct answer to "what is X / 0," if X is a number NOT equal to zero, is "undefined," or "not a number". It is NOT infinity. If X IS equal to zero, by the rules of algebra, while not strictly prohibited, per se, the result can be anything at all and is true even if the input was false, so it really doesn't MATTER.

      Now, some people get confused about the different fields of mathematics. They think that because they're taught in different classes out o

    286. Re:Infinity by vux984 · · Score: 1

      An equation that uses Divide by zero might go to "max limit" or to zero (in practical terms), based on preceding values. It will not suddenly say; "Sorry, the resultant value is indeterminable".

      Using an function where its undefined is fundamentally invalid.

      lets say I define function:

      f(x,y) = 1+ x/y; for all y in R such that y>0; for all x in R such that x>=0

      If I call this function f(-4,2) same thing. Its not defined, its NOT defined for xbased on preceding values

      Its not hard to completely break this.

      Consider sin(1/x)

      http://www.wolframalpha.com/in...

      See what that does? It doesn't merely shoot off to infinity; its clearly bounded between 1 and -1. But nor does it have a clear value at x=0; its limit is undefined at 0.

      http://www.wolframalpha.com/in...

      Limit does not exist.

      It does go towards a finite number, it doesn't go to plus or minus infinity. Its JUST not defined. Don't ask for a value there because there isn't one is the ONLY correct answer.

      The point is, a function is defined on an interval. If there is somewhere where its undefined, it is an error to ask it for a value there. If you are interested in where the function is going, then don't ask it for a value, as it where it going (ie take a limit). But don't be too surprised when you find out there isn't a limit either.

      And don't forget that lots of real world functions have values that don't line up with their limits.

      f(x) = { 2x for all x in R, such that x != 5; 5 if x = 5 } this is a perfectly valid function. The limit of f(x) as x->5 = 10 from the left, and the right; but f(5) = 5.

      You are technically correct but IMHO practically wrong. I'm talking about "real use" such as in animation, graphing and financial.

      I can't imagine a scenario in financial where division by zero should ever be fudged.
      I can't imagine a scenario in graphing where division by zero should ever be fudged.
      In amimation; yes; sometimes you take shortcuts to correctness for performance, but honestly handling division by zero properly tends to be an optimization. You are usually dealing with a vertical line (infinite slope), or a the intersection of a line parallel to a plane or something; and you can and should handle it correctly easily.

      Can you cite an example where not handling a case where division by zero is going to occur properly makes sense to you? Rather than just hand waving that examples exist, can you acutally provide one? Because I can't think of one.

    287. Re:Infinity by Beck_Neard · · Score: 1

      > It's perfectly legitimate to have code which is general which has an input for which zero is a valid value.

      I honestly can't think of any time this could be legitimate. Please give an example. Example requirements: Code must use integer division, must do something useful in the real world, must not be contrived (i.e. not just an integer version of an algorithm that could be done just as well with floating point), and can be fixed using a simple test and branch.

      --
      A fool and his hard drive are soon parted.
    288. Re:Infinity by allo · · Score: 1

      Infinity like java knows it is okay. this constant obeys the usual rules like inf + x = inf

    289. Re:Infinity by allo · · Score: 1

      you algorithm may take care of it.
      This does not mean to set 0/0 = 0, but like "if(denominator == 0){converged=True}"

    290. Re:Infinity by allo · · Score: 1

      math gives you two limits, one being 0, one being 1.

    291. Re:Infinity by Kiwikwi · · Score: 1

      Interestingly, the same issue exists for 0^0 (x^0 = 1 and 0^x = 0 for any x), but here IEEE floating point has standardized on a result of 1, instead of raising an exception.

      Wikipedia on 0^0

    292. Re:Infinity by Anonymous Coward · · Score: 0

      Too lazy to login....

      Seen lots of comments that seem to think you should never ever have a possibility of divide by zero, and if you do there is something wrong with your code.

      There is nothing wrong with having the possibility of it happening, it happens all the time in mathematics. Arguably, the entirety of calculus is just dividing by zero and figuring out how to handle the exception...

      I'm of the belief that every instance that could result in a divide by zero be handled, though have it handled based on context. As an example, I have a 2d and 3d vector class that I wrote where division by zero can occur in the length method. In this context I return 0 if divide by zero occurs as the only way to have division by zero in this context (outside of a random error/bit flip/act of bob, etc) is pass the zero vector as input. The zero vector is a valid vector, could occur in calculations and has zero for length. So why should a function that calculates the length of a vector throw an exception when the length is actually 0?

      For anyone unconvinced, lets say I'm using 3 different vectors to track an object. A position vector, a velocity vector and an acceleration vector. I simulate throwing the object straight up in the air. I have an output that reports the SPEED (length of the velocity vector) of the object. The object experiences gravity and we'll say the x axis is in the direction of gravity so all motion in this case (throwing the ball straight up) occurs along the x direction.

      We'll ignore position for now and stick with velocity and acceleration.

      v = (10, 0, 0)
      a = (-1, 0, 0)

      Each iteration, a will be summed with v to produce the new velocity vector, the length of v will be computed and reported to the user in some fashion.
      After 10 iterations, v = (0, 0, 0) and the length method should report 0 for speed. We don't want to throw an exception as the object is still in motion, just at the apex of it's trajectory (where for a brief instant in time, it motionless) and will have v = (-1, 0, 0) on the next iteration.

      Division by zero should always be checked and handled, handling may involve bailing out and letter the user know what happened, or it may involve reporting a reasonable result and moving on. Having a standard result gains us nothing, and saying your program should never have the possibility of dividing by zero is naïve at best.

    293. Re:Infinity by Anonymous Coward · · Score: 0

      Ugh, haven't had my coffee yet... and realized everything I just wrote was crap. Hooray for not logging in.

      It's the method that finds the unit vector that returns the zero vector if the length is zero, which I use in completely different contexts to the scenario I described above. The length method doesn't involve division. I stand by my conclusion though ;)

    294. Re:Infinity by joeblog · · Score: 1

      Interesting case I hadn't thought of. I'd vote it up, but don't seem to have enough slashdot street cred.

      --
      If it works, it's obsolete
    295. Re:Infinity by Anonymous Coward · · Score: 0

      Positive or negative?

    296. Re:Infinity by Anonymous Coward · · Score: 0

      This kind of trick is used to counteract numerical annihilation, i.e. where a stored value that should be small but nonzero becomes zero because floats aren't computed with infinite accuracy. It's a hack, but if it works, i.e. if it always makes the overall error small enough, it is indeed correct.

    297. Re:Infinity by snowgirl · · Score: 1

      I am not concerning myself with representations of mathematical values, except to show the parallels of why it works. IEEE 754 defines a positive and negative infinity, because it has a specific signed bit. Thus, it's easier to define a positive and negative infinity than to produce special code to handle "exceptions"... note also that IEEE 754 defines a positive and negative 0 separately. No, they really do.

      My model is a theoretical one that hasn't reached mathematical consensus, and it likely never will. I just note that this is an argument for infinity being signless.

      --
      WARNING! This girl exceeds the MAXIMUM SAFE standards established by the FDA for BRATTINESS
    298. Re:Infinity by Anonymous Coward · · Score: 0

      Yay. Finally someone who knows their math. Any number divided by zero is undefined. Zero divided by any number (other then Zero) is Zero. The answer to the question is yes, changing this fundamental principal system wide WILL have bad consequences up to (and including) your system not being able to do mathematics correctly because it's just plain wrong.

      If the author has to constantly check for zero over and over again, then I say that there is something wrong in his system. Division my zero makes no sense mathematically. And whoever said the number is basically infinity.. you're correct. There is no number for which zero goes into any other number.

    299. Re:Infinity by Samantha+Wright · · Score: 1

      I mentioned the +/- zero thing in another comment elsewhere in this tree, actually! So we're all on board there.

      It's not really that signless infinity is a contender for 'consensus' inasmuch as number systems which use signless infinity have utilities different from systems that have signed infinities, just like integer math continues to exist despite the 'improvements' of fractions and decimals.

      --
      Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
    300. Re:Infinity by coolsnowmen · · Score: 1

      Yep. He forgot to substitute x back in. you'd go from: x^2/x to 2x/1, at which point we would substitute x->0 and get 2(0)/1 = 0

    301. Re:Infinity by Anonymous Coward · · Score: 0

      0/0 IS a number, we just don't know what it is because we don't have an example in nature to show us what it is. Either that or Algebra is garbage when it comes to dealing with zeros in the denominator.

    302. Re:Infinity by Anonymous Coward · · Score: 0

      He just said "Rule two: anything divided by itself is one"

      Algebra is incomplete because it can't deal with divide by zero correctly. Either a new definition of zero is needed, or an absolute answer to divide by zero must be found.

      We have no answer yet because mathematicians are lazy.

  14. When a man is tired of checking for divide-by-zero by Anonymous Coward · · Score: 3, Insightful

    ... he is tired of life.

  15. Math doesn't approve by spiritplumber · · Score: 4, Interesting

    Division by zero if anything would be +infinity or -infinity depending on signs, not zero. A while ago I wrote an autopilot that handled division by zero by looking at the signs and setting the result to (maxpos) or (maxneg), the zero's sign being derived from the variable's last value scavenged from the PID function.

    --
    Liberty - Security - Laziness - Pick any two.
    1. Re:Math doesn't approve by Anonymous Coward · · Score: 1

      Divide-by-zero is "not a number" (NaN), *not* infinity, whether positive or negative. An example of something positive or negative infinity would be asymptotes that approach zero and so the sign depends from which direction zero is being approached.

    2. Re:Math doesn't approve by spiritplumber · · Score: 2

      True, but since I knew from which direction zero was being approached, and I can't do navigation math with a NaN, I came up with that solution.

      --
      Liberty - Security - Laziness - Pick any two.
    3. Re:Math doesn't approve by pem · · Score: 1

      Mod parent up. Using infinity sorta, kinda makes sense in some (actually many) instances. Using zero is senseless in any mathematical or practical sense.

    4. Re:Math doesn't approve by brantondaveperson · · Score: 1

      A while ago I wrote an autopilot that handled division by zero ...

      I trust this wasn't in an aircraft that is ever likely to take people anywhere, right?

      I'm actually pretty curious though, you're talking about a PID, and the only divisions in there that I can imagine are in a numerical derivative calculation, which must have meant that your dt went to zero... I'm probably on the wrong track, but I am interested.

    5. Re:Math doesn't approve by spiritplumber · · Score: 4, Interesting

      Well, division by zero should never happen, but you want it to be handled gracefully in case it does. Nobody wants the autopilot in charge of a barge train to segfault. Basically, every variable in the system was stored three times, past value - current value - predicted future value. If I saw a zero, I could use the past value to get the sign of the zero, and work from there.

      --
      Liberty - Security - Laziness - Pick any two.
    6. Re: Math doesn't approve by Anonymous Coward · · Score: 0

      Special functions depending on your case. How things go to infinity or zero or negative infinity is a huge thing, http://dlmf.nist.gov/
      Cardinality matters here

    7. Re:Math doesn't approve by tristes_tigres · · Score: 2

      Nope. Division by zero is NaN if and only if the numerator is zero as well.

    8. Re:Math doesn't approve by Anonymous Coward · · Score: 0

      The rule is it is determinant, and was showed to be that when I was 10 years old, by my programming teacher.

      Division is the opposite of multiplication. If a number /0 = ? then what multiplied by 0 would give you anything? Why any number multiplied by zero, so any number multiplied by 0 = 0 so you cannot determine what number is zeros divisor, so the division by zero is indeterminate. Which a $0.05 cent calculator would give you 'E' for error.

      In the domain of arithmetic, division by zero is indeterminate.

    9. Re:Math doesn't approve by Anonymous Coward · · Score: 0

      Mod parent down:
      Using anything that is not part of the strict mathematical definition, or the IEEE floating point definition does not make sence.

      IEEE would not have sat down, and devised a standard that was useless in this case, and The actual answer known since antiquity would not have any use either:

      https://en.wikipedia.org/wiki/Division_by_zero

      https://en.wikipedia.org/wiki/IEEE_floating_point

      http://grouper.ieee.org/groups/754/faq.html#exceptions

      http://stackoverflow.com/questions/14682005/why-does-division-by-zero-in-ieee754-standard-results-in-infinite-value

      Here: Let me google that for you (**shole).

    10. Re:Math doesn't approve by Anonymous Coward · · Score: 0

      Not just +/- infinite. It is possible that there is a hole in the curve as well which would result in a divide by zero error. This is a bit of a contrived example but think of f(x)= (x*(x-1))/(x-1). This would result in a hole in the curve at x=1. There are some more complex examples that you cant reduce, but I cannot think of one right now.

      Unfortunately it is not a straight forward problem

    11. Re:Math doesn't approve by Anonymous Coward · · Score: 0

      Poor Nan, she can't do math. Let's pass a law to get her some training.

    12. Re:Math doesn't approve by Anonymous Coward · · Score: 0

      No no no. Clearly people are confused by the difference between the $\lim_{x\to a}\frac{f(x)}{g(x)}$ where $\lim_{x\to a}g(x) = 0$ and 0/0. This is like confusing 0^0 with $\lim_{x\to a}f(x)^{g(x)}$ where $\lim_{x\to a} f(x) = \lim_{x\to a} g(x) = 0$. In a ring, if you allow 0 to be invertible, then you get a degenerate ring where everything equals 0. Since the rings we typically use in computers are not degenerate, that is not the case and hence division by 0 is undefined.

    13. Re:Math doesn't approve by BradMajors · · Score: 1

      The result of dividing my zero is not infinity.

    14. Re:Math doesn't approve by sjames · · Score: 1

      Mathematically, yes. In engineering, if you know the direction 0 was approached from, +/- infinity makes sense. In many cases, maxval and minval are good enough and will work out at the practical level (where engineering lives).

    15. Re:Math doesn't approve by Anonymous Coward · · Score: 0

      That's OK, infinity isn't a number either.

    16. Re:Math doesn't approve by myowntrueself · · Score: 1

      Division by zero if anything would be +infinity or -infinity depending on signs, not zero.

      A while ago I wrote an autopilot that handled division by zero by looking at the signs and setting the result to (maxpos) or (maxneg), the zero's sign being derived from the variable's last value scavenged from the PID function.

      If x/0 = some constant, whatever that constant might be whether infinity, zero, 8 or whatever, you get this:

      x/0 = c = y/0 therefore x = y for all numbers.

      So all numbers are equal and mathematics completely breaks down.

      --
      In the free world the media isn't government run; the government is media run.
    17. Re:Math doesn't approve by Palinchron · · Score: 1

      Well, division by zero should never happen, but you want it to be handled gracefully in case it does.

      You are aware that segfaults are there specifically as a graceful handling of error conditions, right? We could just have every invalid memory access return 17 if we preferred. You seem to be underestimating just how nongraceful not aborting would be. The alternative to a segfault is a program that could go do absolutely anything, unpredictably.

      Nobody wants the autopilot in charge of a barge train to segfault.

      I would much prefer that over the autopilot deciding that its current speed is [broken computation... division by zero... "zero"] and the desired speed is 50km/h, so hit the accelerator until the division by zero situation resolves itself.

      --
      The lesson here is that a sufficiently large corporation is indistinguishable from government. --ultranova
    18. Re:Math doesn't approve by pem · · Score: 1

      How the fuck is the segfault graceful when it aborts a program handling hardware? You're just like one of those idiots who programmed "oh, the best thing to do if I don't know what's going on is to shut down this engine -- the other 3 will still fly the plane OK."

    19. Re:Math doesn't approve by Anonymous Coward · · Score: 0

      IME whenever I divide by zero (and neglected to check for such a condition before doing so) it's because my data is fucked and I cannot trust it, meaning there is probably a bug that happened earlier in my program.

      I learned very early on in my career to check for error conditions and handle them as gracefully as possible even if this just means reporting the fact that there was an error.

      I once went to work for a company that managed 401(k) plans. My boss was an accountant who had "learned" to program (meaning he probably spent 1-2 weeks in "training"). There was a lot of SQL but absolutely no error checking. There were also no transactions (No "BEGIN WORK", no "COMMIT WORK" and certainly no rollback statements).

      My boss noticed I was adding such things as well as logging any errors that may occur. He said "I hope you're just doing that [error checking] for testing."

      At another place someone told me "I don't need to check for errors after that [SQL] statement. There's no way it can fail."

      Those are pretty much verbatim quotes (one from a former boss and one from a co-worker) as best as I can remember. The sentiment if not the exact words was there.

      My boss was horrified that a user might see an error message but completely unconcerned that someone's 401(k) might be fucked.

      My co-worker (different employer) was so confident in his code that a database statement he wrote could not possibly fail.

      At yet another place I worked we had "rigorous standards" and we always checked for errors and reported them and rolled back when there was an error.. There was this one monster of a program that batch processed a bunch of shit. It was slow and usually heavily customized for each of our customers and sometimes it failed and when it failed it was a fucking nightmare if it didn't fail gracefully (as much as we tried to make it fail gracefully and rollback all the shit).

      One day I got a call from our biggest customer. It had failed and as a result they had hundreds of union employees making zillions of dollars an hour just sitting on their asses because our software was down.

      It took me a few hours (while they escalated up their chain of command and our chain of command breathing down my neck - I didn't even work on their account much). Finally, I figured it out. One of our bright (possibly H1-B? I'm not sure of his status, definitely not a fluent English speaker) had decided it was a good idea to just reset the error code variable back to ZERO because "who cares if that function fails on that one order line out of thousands we're processing? It's not worth it to stop the whole fucking thing!" (those were not his exact words - just what I imagine him thinking).

      I would agree with him except for one thing. This error didn't just screw up ONE order line. It screwed up that order line and every fucking order line after that that it had processed. Nobody could do anything. Inventory was fucked. We couldn't just restart the process.

      All for the lack of good error checking and failing gracefully.

  16. Infinity by Anonymous Coward · · Score: 0

    Howabout infinity?

  17. Why have the post counts moved? by turp182 · · Score: 1

    Really?

    --
    BlameBillCosby.com
    1. Re:Why have the post counts moved? by amicusNYCL · · Score: 2, Insightful

      Apparently so that everyone can hit some stupid Share button by mistake instead.

      --
      "Our two-party system is like a bowl of shit looking at itself in a mirror." - Lewis Black
    2. Re:Why have the post counts moved? by blue+trane · · Score: 1

      I agree with this comment.

  18. Bury Head in Sand by NickAragua · · Score: 4, Interesting

    This idea reminds me of "On Error Resume Next". The reason you don't do that is because a divide by zero indicates that you've got a logic failure somewhere else in your code. It's frequently easier to find an error when it's flashing big and red and throwing exceptions, rather than failing silently.

    1. Re:Bury Head in Sand by Anonymous Coward · · Score: 2, Funny

      He could be a mySQL programmer.

    2. Re:Bury Head in Sand by neilo_1701D · · Score: 2

      This idea reminds me of "On Error Resume Next".

      The reason you don't do that is because a divide by zero indicates that you've got a logic failure somewhere else in your code.

      Or a data input failure.

      If I'm streaming data in from a sensor, I expect there to be the odd data failure. Or lost packet. Or alpha particle hitting a memory core. Or something.

      My logic might be perfect; if the data is screwy and I pass it in to process it, well that was a silly move.

      I'd prefer 100 lines of validation code to throw out bad data before it hits the processing code than 10,000 lines of code to validate within the data processing.

      But that's just me.

    3. Re:Bury Head in Sand by sjames · · Score: 1

      Sometimes it really is a pathological corner case and it really will work out fine if you "kick the table leg" and get on with it.

    4. Re:Bury Head in Sand by sjames · · Score: 1

      On the other hand, if you can throw it out with 2 lines of code in processing and you are space constrained, it may be good enough to just paste over the div by zero by making that input value never happened.

  19. Is this for real? by Anonymous Coward · · Score: 0

    I'm assuming you're talking about integers?

    I've always seen IEEE 754 floats give NaN for division by zero, which is fine by me.

    Division by zero with Integers (which have no representation of NaN) sounds like an exception case to me. It should definitely *NOT* be zero, if for no other reason for the fact that division by zero is undefined. If you need it to be zero in your programs, keep doing what you're doing, but in the general case, having that be the default is absurd!

    1. Re:Is this for real? by Lord+Crc · · Score: 1

      I've always seen IEEE 754 floats give NaN for division by zero, which is fine by me.

      You get +/- infinity if a non-zero number is divided by zero, with the sign taken from the denominator. You only get NaN (not a number) if you divide zero by zero.

    2. Re:Is this for real? by Lord+Crc · · Score: 1

      with the sign taken from the denominator

      Should of course be "with the sign taken from the numerator".

      I'll go to bed now...

    3. Re:Is this for real? by gurps_npc · · Score: 1
      One of the major misunderstandings about math is that it is a science.

      It is NOT a science - it is a language. (Note String theory has the same issue.)

      As such it can be sued to descr4ibe things - both true things and false things. I can easily write 1+1=3, and I can even describe a universe where that is an axiomatic principle. It is not THIS universe, but it is a theoretical one. Another, easier to understand rule like this is setting the the sum of the angles of a triangle = 190 degrees. This does not work in flat space, but if space is curved by gravity, say near a black hole...

      Setting x/0 = 0 is a legitimate choice for some issues, but it may cause major problems in others.

      I would not advise making this kind of change.

      --
      excitingthingstodo.blogspot.com
  20. umm by NEDHead · · Score: 2

    no, because div by zero is not equal to zero

    1. Re:umm by Zocalo · · Score: 1

      Not just that, but using zero as a default error value for X/0 also fails to take into account the possibility of 0/X for which zero is the correct (and desirable) answer. X/0 != 0/X, so they *need* to return different values.

      --
      UNIX? They're not even circumcised! Savages!
  21. Really by Anonymous Coward · · Score: 0

    Divide by 0 is not 0. I would never want my results to be set to 0 for divide by 0. If anything it would need to be set to infinity, but even that will cause your data to be off.

  22. Because zero is the wrong answer by RealityGone · · Score: 0

    Division by zero doesn't equal zero. It equals infinity. If anything I want to get a NULL or NaN returned. Division by zero is an exceptional case and it should be treated as such. (By throwing an exception!) Should we also make pi equal to 3 so it's easier to find the area of a circle?

    1. Re: Because zero is the wrong answer by Anonymous Coward · · Score: 0

      It is so much more than this, http://dlmf.nist.gov/

  23. n/0 != 0 by Anonymous Coward · · Score: 0

    Pretty sure that anything divided by zero is an uncountable infinity. You may want it to be 0, but it mathematically isn't.

    1. Re:n/0 != 0 by gnupun · · Score: 1

      Technically, the result in undefined, hence the exception is generated. However, practically speaking, for divisors close to zero but not zero, the result is +/- infinity, which is what happens in floating point code.

    2. Re:n/0 != 0 by myowntrueself · · Score: 1

      Pretty sure that anything divided by zero is an uncountable infinity. You may want it to be 0, but it mathematically isn't.

      If x/0 = some constant, whatever that constant might be whether infinity, zero, 8 or whatever, you get this:

      x/0 = c = y/0 therefore x = y for all numbers.

      So all numbers are equal and mathematics completely breaks down.

      --
      In the free world the media isn't government run; the government is media run.
  24. Because 1/0 != 0? by mlts · · Score: 2

    I'd rather either have an exception thrown or a "NaN" value used than a zero returned. A divide by zero error is nasty, but just "papering over" it by returning a zero is only going to introduce more subtle bugs in the code.

    1. Re:Because 1/0 != 0? by Anonymous Coward · · Score: 0

      Generally speaking the *only* time you want X/0 to be '0' is when you're displaying output in a report, and someone specifically *tells* you that's what they want to see when you divide by zero. Better still is to detect the situation, and display '-', 'n/a', or something else which calls out the fact that you don't actually *have* a value for that.

    2. Re:Because 1/0 != 0? by joemck · · Score: 1

      Exception yes, NaN no. NaNs suck. An exception takes you right to the problem, or close to it. NaN spreads over your variables like kudzu, since any calculation involving it results in NaN. Sure it tells you there's a problem, but by the time you see it, half your variables are NaN and you're left trying to figure out where it came from.

    3. Re:Because 1/0 != 0? by Anonymous Coward · · Score: 0

      Exception:yes. NaN: no, unless it's 0/0.

      IEEE floating point exceptions:

      Division by zero (an operation on finite operands gives an exact infinite result, e.g., 1/0 or log(0)) (returns ±infinity by default).

      NaNs with indeterminate forms

      The divisions 0/0 and ±inf/±inf
      The multiplications 0x±inf and ±inf×0
      The additions inf + (-inf), (-inf) + inf and equivalent subtractions
      The standard has alternative functions for powers:
              The standard pow function and the integer exponent pown function define 0^0, 1^inf, and inf^0 as 1.
              The powr function defines all three indeterminate forms as invalid operations and so returns NaN.

      *Note: I've modified the above block quote so it'll display reasonably on /; I replaced infinity sign with inf, a multiplication sign followed by a +/- sign with x because it didn't show either sign, and I inserted carets for superscript.

  25. I'm tired, too by linuxwrangler · · Score: 5, Funny

    Hi SlashDot. I'm a programmer who is tired of sanitizing inputs and checking for exceptions. Can you suggest a way to change the world so those things don't exist?

    --

    ~~~~~~~
    "You are not remembered for doing what is expected of you." - Atul Chitnis
    1. Re:I'm tired, too by 31415926535897 · · Score: 5, Funny

      Code in PHP

    2. Re:I'm tired, too by Livius · · Score: 1

      Not-a-number is at least a suitable return value, though not necessarily the best response.

      Zero is simply incorrect.

    3. Re:I'm tired, too by Anonymous Coward · · Score: 4, Interesting

      Yes. I wrote a 3D modeling program a very long time ago. It involved a lot of fractions and subtracting. Lines that were perfectly horizontal or vertical would result in divide-by-zero errors, since X1-X2 in the denominator was disastrous.

      So I rotated the entire universe by an irrational number of degrees on each axis. The problem went away.

    4. Re:I'm tired, too by Darinbob · · Score: 1

      "It's so crazy that it might just work!"

    5. Re:I'm tired, too by Darinbob · · Score: 1

      I suggest that you give up on programming and go into marketing. The hours are better and you still get to take credit for what the programmers do.

    6. Re:I'm tired, too by RDW · · Score: 1

      No, but welcome to Adobe, Mr Wrangler! As your first task, it will be your responsibility to ensure that our award-winning Acrobat Reader and Flash products retain their legendary online security reputations.

    7. Re:I'm tired, too by Anonymous Coward · · Score: 0

      Lets see here...

      ?php

      echo 0 / 0;

      $ php python_coders_suck.php

      PHP Warning: Division by zero in /home/jtx/zero.php on line 3

      seems fine to me

    8. Re:I'm tired, too by Seatche · · Score: 1

      How about a "divide by zero" error, since this is less of a non-answer as NAN? Why not be more specific?

      --
      I'm bad with sayings, so just go live life for crying out loud.
    9. Re:I'm tired, too by swilly · · Score: 1

      Stupid Slashdot doesn't have a way to undo a moderation other than posting. I meant to select Funny, and hit Overrated instead.

    10. Re:I'm tired, too by gnu-sucks · · Score: 1

      if(x1!=x2)
      {
      slope = (y2-y1) / (x2-x1);
      }

      If x1 == x2, you probably don't actually *need* a slope. You can mark those shapes or lines as perfectly vertical. Any algorithms that process based on slope would just skip those lines. A simple bool array that accepted pixel or shape (not really sure of the application) coordinates could return several useful parameters that would keep other algorithms from tripping up.

      You might think this is a lot of overhead, but passing uint(-1) to an algorithm needlessly, or rotating your entire scene to avoid this is also a lot of overhead. If you just make a single pass over the scene and store the parameters (remember, memory is plentiful these days compared with CPU), then you can do very simple logic on the processing side, re-using the stored results.

      You can fix the math by fixing the algorithm, no need to return results when the results are not only undefined but also not useful.

    11. Re:I'm tired, too by Anonymous Coward · · Score: 0

      Damn, I was going to post that! Your version was more concise.

      I don't think I have ever read a Slashdot topic with more universal consensus! The original post is a troll, right? Please tell me it is so?

    12. Re:I'm tired, too by Anonymous Coward · · Score: 0

      Thank god I don't use your program. You are the reason my CAD programs crash.

    13. Re:I'm tired, too by tristes_tigres · · Score: 1

      Good example of a wrong way to solve the problem.

    14. Re:I'm tired, too by Anonymous Coward · · Score: 0

      Code in PHP

      Or BBC Basic that merely handled division by 0 conditions as infinite., this was very useful when writing graphing programs on the BBC.

  26. It's irrational by Coldeagle · · Score: 1

    And we all know that computers are ALWAYS rational :P

    1. Re:It's irrational by Anonymous Coward · · Score: 0

      Not sure if you're joking about 1/0 being irrational or not, but 1/0 is not irrational. It's not a number.

    2. Re:It's irrational by Quirkz · · Score: 1

      Thus, it must be a letter! Except in hexadecimal notation letters are numbers, so 1/0 is a color?

  27. Zero is wrong... by snowsmann · · Score: 0

    First issue, x/0 mathematically is infinity, not zero. Plus, you want the same exact result across all applications ever? There are certainly times where zero is appropriate, there are also many times when one would want to have some representation of infinity; yet others where this simply indicates an error of some other sort and zero is a valid result.

    --
    timeo Danaos, et dona ferentis
    1. Re:Zero is wrong... by Livius · · Score: 1

      First issue, x/0 mathematically is infinity, not zero.

      Which infinity? There are many.

    2. Re:Zero is wrong... by snowsmann · · Score: 0

      Exactly. Another reason to not have some dumb default value come up. Mathematically it isn't even infinity conclusively all the time. It is really undefined. Generally speaking it becomes either positive or negative infinity when the division is one which makes sense to evaluate under a limit. Just endless reasons to not do something as asinine as defaulting x/0 = 0

      --
      timeo Danaos, et dona ferentis
    3. Re:Zero is wrong... by FranTaylor · · Score: 1

      Which infinity? There are many.

      I think this counts as an "understatement"

    4. Re:Zero is wrong... by lenart · · Score: 2

      First issue, x/0 mathematically is infinity, not zero. Plus, you want the same exact result across all applications ever? There are certainly times where zero is appropriate, there are also many times when one would want to have some representation of infinity; yet others where this simply indicates an error of some other sort and zero is a valid result.

      Actually, mathematics does not define the result of x/0 (except in the extended complex plane or Reimann sphere, the answer there is complex infinity). I also fail to see when zero is an appropriate answer. If an application is asked to divide by zero, any subsequent result that uses the outcome of that division will not be mathematically valid. Surely one can see that the application should stop the calculation and report to the user.

    5. Re:Zero is wrong... by snowsmann · · Score: 0

      I "corrected" myself (went into better detail in another reply) but I do agree with what you are saying here. I think my engineering brain just defaults to look at everything as if it were under a limit (-;

      --
      timeo Danaos, et dona ferentis
    6. Re:Zero is wrong... by amicusNYCL · · Score: 1

      The sixth infinity.

      --
      "Our two-party system is like a bowl of shit looking at itself in a mirror." - Lewis Black
    7. Re:Zero is wrong... by myowntrueself · · Score: 1

      First issue, x/0 mathematically is infinity, not zero. Plus, you want the same exact result across all applications ever? There are certainly times where zero is appropriate, there are also many times when one would want to have some representation of infinity; yet others where this simply indicates an error of some other sort and zero is a valid result.

      I've rarely seen such crap posted on /. pretending to be knowledgeable.

      If x/0 = some constant, whatever that constant might be whether infinity, zero, 8 or whatever, you get this:

      x/0 = c = y/0 therefore x = y for all numbers.

      So all numbers are equal and mathematics completely breaks down.

      --
      In the free world the media isn't government run; the government is media run.
    8. Re:Zero is wrong... by clovis · · Score: 1

      First issue, x/0 mathematically is infinity, not zero.

      That is not quite right.
      Division by zero is undefined, or as some say, indeterminate.

  28. Identities by outlaw · · Score: 1

    Please don't forget that dividing by zero is *not* always zero (or, simply, undefined) !

    Anything divided by itself is one - something most everything but APL gets incorrect :-(

    1. Re:Identities by Anonymous Coward · · Score: 0

      Anything divided by itself is one, except for 0. 0/0 is not 1; it is undefined.

      Strictly speaking, a non-zero value divided by 0 can be infinite or undefined, depending on the circumstances (look it up on Wikipedia), but division by 0 never results in a number.

    2. Re:Identities by Anonymous Coward · · Score: 0

      Anything divided by zero is *never* zero.
      It's either undefined or undetermined.

    3. Re:Identities by Fwipp · · Score: 3, Insightful

      No, 0/0 is still undefined.

    4. Re:Identities by Anonymous Coward · · Score: 0

      The identity function for division is x/1=x, NOT x/x=1. There reason for this is precisely due to the case of x=0. x/x=1 can be trivially derived from x/1=x, BUT ONLY IF x != 0.

  29. I don't want dive-by-zero to be zero by Anonymous Coward · · Score: 1

    In answer to your last question, yes, there are lots of people who do not want divide-by-zero to be zero. Mostly because it is completely wrong and hides mistakes in what one is trying to do. A divide by zero error means there are cases that have not been considered in the design of your algorithm, equation, what-not. Masking that by silently returning not just an answer, but an answer that is completely non-contiguous with the nearby answers is a $100M-probe-crashing-into-the-surface-of-mars problem just waiting to happen.

  30. no by Anonymous Coward · · Score: 0

    also, lets set pi to equal 3

    1. Re:No by suutar · · Score: 1

      Does anyone want their div by zero errors to result in anything other than zero?

      Yes.

      No.

      File not found.

    2. Re:no by Xtifr · · Score: 2

      Honestly, I think I'd prefer having pi defined as three than have division by zero return zero. My answers will at least be in the right domain even if the value is off a bit.:)

    3. Re:No by Anonymous Coward · · Score: 0

      Peppers!

    4. Re:No by JustOK · · Score: 1

      File not found. Try sandpaper.

      --
      rewriting history since 2109
    5. Re:No by Immerman · · Score: 1

      I was waiting for this one...

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    6. In a world gone mad, where pi is (int) 3 and dividing by 0 has a value, terror stalks the halls.

      --
      "There is no god but allah" - well, they got it half right.
    7. Re:no by gzuckier · · Score: 1

      Honestly, I think I'd prefer having pi defined as three than have division by zero return zero. My answers will at least be in the right domain even if the value is off a bit.:)

      Pi is three! The Bible does not lie!
      1 Kings 7:23
      And he made a molten sea, ten cubits from the one brim to the other: it was round all about, and his height was five cubits: and a line of thirty cubits did compass it round about.

      It's easy to tell that the 3.14.... number is a Satanic Lie; merely add the first 144 digits. What do you get? 666!!!!!

      --
      Star Trek transporters are just 3d printers.
  31. This is why we have NaN by Zontar+The+Mindless · · Score: 1

    The reciprocal of x increases as x decreases.You want infinity, not zero, for x=0.

    --
    Il n'y a pas de Planet B.
    1. Re:This is why we have NaN by cruff · · Score: 1

      Well, the limit of 1/x as x approaches 0 from the positive side is +Inf, but the corresponding limit as x approaches 0 from the negative side is -Inf. Still no way to choose just one as "correct". Thus by various definitions, 0/0 = NaN, indicated with either a floating exception program termination, or a signalling or non-signalling IEEE NaN depending on the environment and if your code has adjusted various FP environment options.

    2. Re:This is why we have NaN by gnu-sucks · · Score: 1

      Just take the mean:
      mean(-inf, +inf) ...which is zero. Oh wait hmm...

      (yes I realize the multiple fallacies here, this is intended as a joke)

    3. Re:This is why we have NaN by myowntrueself · · Score: 1

      The reciprocal of x increases as x decreases.You want infinity, not zero, for x=0.

      If x/0 = some constant, whatever that constant might be whether infinity, zero, 8 or whatever, you get this:

      x/0 = c = y/0 therefore x = y for all numbers.

      So all numbers are equal and mathematics completely breaks down.

      --
      In the free world the media isn't government run; the government is media run.
  32. Just... don't. by mujadaddy · · Score: 1

    You're asking about redefining what division means. Dividing by zero means taking the original term and putting it into ZERO groups. That is not defined. It's that simple. Now, I'm the type of person who'll discuss this, but you've not really given any reason for it to be defined as the quantity zero, so here's your chance.

    --
    Populus vult decipi, ergo decipiatur...
    "Force shits upon Reason's back." - Poor Richard's Almanac
  33. Why zero? by Anonymous Coward · · Score: 0

    Let's go with division by zero giving an arbitrary answer, but why stick with zero? If it's floating point, it should definitely return phi. For integer types, it should return the largest legal value made up of repeating the decimal digits "8675309".

    While we're at is, all boundary errors should be accepted with a simple warning of "Inconceivable!"

    Oh, and we need seven red lines, all of them strictly perpendicular, some with green ink and some transparent. Oh, and one in the form of a kitten.

  34. Divide by zero is NOT zero. It is an error by Steve+Newall · · Score: 1

    "Does anyone want their div by zero errors to result in anything other than zero?". I think the answer is yes, a divide by zero is NOT zero, it is an error. I would like my divide by zero to generate an error.

  35. well.. by Anonymous Coward · · Score: 0

    I can see that only if you try 0/0... the fact that you're trying to divide should have precedence over the fact that you're trying to divide it. Otherwise, if my application is trying to divide a number by, well... nothing, I'd like to have an exception please. (basically it's like saying "could you please do a divide operation to not divide my value please)

  36. Yes by Anonymous Coward · · Score: 0

    Yes, I want it to result in NaN.

  37. Use 1 ? by Anonymous Coward · · Score: 0

    Wouldn't it be 1?

    For all n, wouldn't n/n=1 ?

    1. Re:Use 1 ? by outlaw · · Score: 1

      Yes, according identity relationships, n / n == 1.

      But, as I mentioned above, APL is the only language I am aware of that got this correct.

    2. Re:Use 1 ? by Anonymous Coward · · Score: 0

      0/0 is not defined. Neither is 0^0 for that matter (n^0=1 for all n != 0)

    3. Re:Use 1 ? by Anonymous Coward · · Score: 0

      Yes, according identity relationships, n / n == 1.

      But, as I mentioned above, APL is the only language I am aware of that got this correct.

      0 * x == 0, so this should hold true when x holds the reciprocal of n, whatever that is when n==0.
      Which correct answer is correct?
      IMHO returning 0 is not the correct answer. APL likely generated 1 due to it (initially) being interpretive and performing a test for equality could bypass the division code resulting in (sometimes) faster results. Some of the older systems could quickly generate the reciprocal then perform a multiplication. This sacrificed some accuracy for performance.
      If you do not like the program halts to your code, then either fix your code or add an exception handler, then return whichever wrong answer you want. NaN for floating point. You might choose -0 for integer, where -0 is defined as having the sign bit = 1 and all the remainder bits = 0. When this value is placed into X then X==-X, which mathematically can only happen when X is zero.

    4. Re:Use 1 ? by Anonymous Coward · · Score: 0

      No, n/n=1 is only true for 'all n where n =/= 0'.

    5. Re:Use 1 ? by david_thornley · · Score: 1

      For all non-zero n, n/n == 1, since 1 is the only X such that n * X == n. If n is zero, any X will work just fine.

      It is possible to assign values to the limit of an expression. As n goes to zero, n / n remains 1. Also, as n goes to zero, 2n / n remains 2. With n == zero, though, n == 2n, so the value of a limit resulting in 0/0 depends entirely on how you got to the limit and not what the final expression is. If you just write 0/0, you're not specifying any sort of expression, and so the value could be any number.

      You can argue that if you write n/n, and n happens to be zero, the right answer is 1. I'm not sure this is nearly as useful as throwing or returning NaN, but there's a mathematical basis for it. If you write n/m, and both n and m happen to be zero, and n and m have no guaranteed relation to each other (like m == sin(n) or something), there's no good argument for any value.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    6. Re:Use 1 ? by Anonymous Coward · · Score: 0

      n/n == 1 is not the identity function for division, n/1 == n is. This is specifically because of the n == 1 case.

    7. Re:Use 1 ? by Anonymous Coward · · Score: 0

      Damn it... n==0.

  38. Other errors by Stephenmg · · Score: 1

    When I get a divide by zero error, sometimes it is because I made some other error such as mis-spelling a variable name or maybe my database connection is broke. Less of an issue with TDD or BDD, but it makes me go back and evaluate if I really expect zero to be a valid value.

  39. gird yourself for the coming NERDRAGE onslaught! by Anonymous Coward · · Score: 0

    (score : -Nan), flambe'

  40. How about catching and handling SIGFPE? by Krishnoid · · Score: 1

    It seems like catching SIGFPE and handling the floating-point/int div-by-zero cases specifically could help you work around this.

    1. Re:How about catching and handling SIGFPE? by Anonymous Coward · · Score: 0

      It seems like catching SIGFPE and handling the floating-point/int div-by-zero cases specifically could help you work around this.

      and then letting us know what the name of this package is so that we can be sure never to rely on it.

    2. Re:How about catching and handling SIGFPE? by petermgreen · · Score: 1

      It's generally a bad idea.

      Some CPUs simply don't support generating floating point exceptions. Even where they are supported the details are likely to vary between platforms. In C programs you have to explicitly turn them on and libaray code may break if you do unless you turn them off before the library calls. Finaly a signal fundamentally means the CPU did a software interrupt that was handled by the kernel and passed back up to the program, it's a fundamentally expensive operation.

      If you know your code will only be used on one platform*, you don't use library functions or you know the ones you use are fpe-safe and you know the case that will trigger the signal is really highly exceptional it might be worth considering, otherwise don't do it.

      * And I REALLY mean one platform, for example vfpv2 supports them, vfpv3 made them an optional feature and in practice I've never come across a vfpv3 implementation that supported them.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
  41. ... but it isn't zero! by Anonymous Coward · · Score: 0

    The problem is that it is actually an unknown value.
    Infinity is closer to the math answrer, but that takes too many bits to encode.

  42. Why so many divide by zero errors? by hawguy · · Score: 1

    Dividing by zero is, by definition, undefined, why would you want divide by zero to be equal to zero? If you don't trap it and handle it appropriately, you'll be generating undefined results.

    What is the use case for having divide by zero equal to zero? (except, perhaps for 0 / 0 where you really want it to be zero, but I can't think of any other case where having any number divided by zero equal to zero would give correct behavior).

    1. Re:Why so many divide by zero errors? by Ketorin · · Score: 1

      Doing it the error checking in shitty way around, that is you expect some result other than zero and check for that.

      In that regard the result of zero integer division is kind of logical: diveder gets too big: zero, diveder gets too smal: zero again, albeit this happens only on one single case: when divider is zero. It essentially says "integer division out of bounds".

  43. Don't pretend everything's OK by Anonymous Coward · · Score: 4, Insightful

    There's a reason you're calculating a division. That number is supposed to be used for something. If your program is dividing by zero, the data it's working with is wrong. The consequences of just pretending to have a valid answer could vary from totally harmless to nuclear winter. But what's the upside?

    1. Re:Don't pretend everything's OK by geminidomino · · Score: 1

      But what's the upside?

      Submitter doesn't have to figure out how exceptions work.

  44. Fuck your web monkeys by Lunix+Nutcase · · Score: 0

    Wow comments actually work again. Good thing you're pushing untested code into production, Dice!

    1. Re:Fuck your web monkeys by Anonymous Coward · · Score: 2, Funny

      Good thing you're pushing untested code into production, Dice!

      Well, you see, they had this divide by zero error ...

  45. hey that's a good idea by Anonymous Coward · · Score: 0

    Great idea !

  46. Infinity (max Float64) seems reasonable by tomxor · · Score: 3, Insightful

    Zero doesn't make a lot of sense if for instance you are dividing something by a dynamically changing denominator that hits zero at some point... the result would change from a very large number suddenly to 0.

    Divide by zero is infinity so using the largest supported number type seems reasonable for the calculation of real numbers.

    1. Re:Infinity (max Float64) seems reasonable by Anonymous Coward · · Score: 0

      Really? So x/0 == infinity when x == -1, then?

    2. Re:Infinity (max Float64) seems reasonable by thegarbz · · Score: 1

      Are you talking about -0 or +0? 1/-0.01 is not a large number. 1/-0.0001 is even smaller. So as you approach zero why would you default to the large number? It certainly doesn't happen in mathematics.

      The only "correct" response for a div by zero is to throw an error or produce NaN as a result. A division by zero is no more infinity than the sqrt(-4) is 2. It's not, or maybe it is. We don't know, and many mathematical constructs have multiple answers.

      You could maybe make the case for producing the largest number when working with an unsigned type but definitely not as a general rule, but then unsigned types don't have a representation for infinity do they?

    3. Re:Infinity (max Float64) seems reasonable by Archangel+Michael · · Score: 1

      If you're running a program that is expected to see a x/0 problem, sanitize it before processing it. Period.

      --
      Agent K: A *person* is smart. People are dumb, stupid, panicky animals, and you know it.
    4. Re:Infinity (max Float64) seems reasonable by Anonymous Coward · · Score: 0

      Division by zero is not "infinity" since infinity is not a number but a concept.
      Division by zero is indeterminate.

      Actually, in the IEEE floating point spec division by zero produces a special result already, NaN, which stands for Not A Number. All you have to do is recognize that value to realize that there has been an error.

    5. Re:Infinity (max Float64) seems reasonable by dcollins · · Score: 1

      "Divide by zero is infinity"

      Yes, in the extended complex plane (Reimann sphere); however the "infinity" there is both complex and sign-less and doesn't match any standard computer number format.

      No, in the extended real numbers (which has +INF and -INF, similar to standard computer systems), because defining 1/0 = +INF would still cause a contradiction.

      "The expression 1/0 is not defined either as +INF or INF, because although it is true that whenever f(x) -> 0 for a continuous function f(x) it must be the case that 1/f(x) is eventually contained in every neighborhood of the set {INF, +INF}, it is not true that 1/f(x) must tend to one of these points. An example is f(x) = (sin x)/x (as x goes to infinity). (The modulus |1/f(x)|, nevertheless, does approach +INF.)"

      https://en.wikipedia.org/wiki/Extended_real_number_line
      https://en.wikipedia.org/wiki/Riemann_sphere

      --
      We know where leadership by an anti-intellectual "strongman" who scapegoats minorities and likes boisterous rallies goes
    6. Re:Infinity (max Float64) seems reasonable by Anonymous Coward · · Score: 0

      sweet, and we even have +0 and -0 support in floating point formats to determine that 1/+0 is +int and 1/-0 is -inf!

    7. Re:Infinity (max Float64) seems reasonable by gweihir · · Score: 1

      FAIL. +inf and -inf are NOT equal to max(float64). That would be even more problematic than the utterly stupid proposal by the OP.

      --
      Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
    8. Re:Infinity (max Float64) seems reasonable by myowntrueself · · Score: 1

      Zero doesn't make a lot of sense if for instance you are dividing something by a dynamically changing denominator that hits zero at some point... the result would change from a very large number suddenly to 0.

      Divide by zero is infinity so using the largest supported number type seems reasonable for the calculation of real numbers.

      If x/0 = some constant, whatever that constant might be whether infinity, zero, 8 or whatever, you get this:

      x/0 = c = y/0 therefore x = y for all numbers.

      So all numbers are equal and mathematics completely breaks down.

      --
      In the free world the media isn't government run; the government is media run.
  47. But that's wrong. by Ultra64 · · Score: 1

    Dividing by zero *should* crash your program.

    What if you were depending on the result of that division to determine which function to call.

    if(x == 0) doThis();
    else doThat();

    An incorrect result of 0 could lead to unpredictable results, which is bad for a program. It's better to make sure your input is clean so it doesn't come up in the first place.

  48. Wat? by Anonymous Coward · · Score: 0

    >>Does anyone want their div by zero errors to result in anything other than zero?

    Yes. Almost everyone.

  49. other options ... by happyjack27 · · Score: 1

    I've often used "1" as a drop in when dividing by zero. also the logarithm of zero, i usually am working with information units, so it's plnp, and if p = 0, i just say that plnp = 0, and that's kind of like saying ln0 = 1.

    i think mathematically infinity or negative infinity would make the most sense, unless its 0/0, in which case you'd apply l'hopital's rule. but i don't think the computers going to do that. another way is you could create another number system, that would run a tally of divides by zeros or multiplies by infinities, minus multiplies by zeros or divides by infinity. (and flipping the sign on negative infinity.)

    1. Re:other options ... by amicusNYCL · · Score: 1

      Real programmers use 17.293884261109482 to represent division by zero.

      --
      "Our two-party system is like a bowl of shit looking at itself in a mirror." - Lewis Black
  50. Hmmm...no by Anonymous Coward · · Score: 0

    It is bad because given some function f(k) = 1/k the last thing you want to do is to have S(x) = f(x-5) + 3 return 3 when x = 5 instead of a BIG FAT ERROR.

  51. Unexpected behavior by Anonymous Coward · · Score: 0

    The same reason you can't divide by zero in mathematics is the reason you cannot reassign divide by zero in computing. It's a logical impossibility. Making it possible (for example, in the famous "proof that 1 = 2") turns whatever logic you are using the result of a division by zero into a train wreck of causality.

  52. The reasons for validating fields by seven+of+five · · Score: 1

    Unfortunately, no, you can't just say screw it, from now on x/0 = 0. If the divisor, for example is an hourly rate and you're trying to calculate hours worked from total pay, the fact that one record contains a zero may mean deeper problems exist that deserve to be flagged.

    If you haven't learned the general principle of checking shit after 20 years...

  53. USS Yorktown anyone? by Anonymous Coward · · Score: 1

    Yes, what could possibly go wrong from no handling a dive by zero. https://en.m.wikipedia.org/wiki/USS_Yorktown_(CG-48)

    1. Re:USS Yorktown anyone? by amicusNYCL · · Score: 1

      I thought it was the USS Eldridge that had the divide by zero issue.

      --
      "Our two-party system is like a bowl of shit looking at itself in a mirror." - Lewis Black
  54. Harm? by Anonymous Coward · · Score: 0

    The harm is that it's not mathematically correct, and it's never a good thing to hobble the correctness of a program just because the coder's too damned lazy to validate his data.

    1. Re:Harm? by Lunix+Nutcase · · Score: 1

      But this is posted to Slashdot whose own coders don't even validate the correctness of the code before they make it live. Such laziness really fits in with the Dice.com mentality.

    2. Re:Harm? by david_thornley · · Score: 1

      This is in full accord with the fact that the editors often get things entirely wrong, and we have to have commenters do that work. Slashdot is ALL about the community.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  55. Zero? Really? by Anonymous Coward · · Score: 0

    Does anyone want their div by zero errors to result in anything other than zero?

    <audio voice="Samuel L. Jackson">Hell yes.</audio>

    What do you mean by equal to zero? there are well defined values for division by zero: Inf and -Inf for nonzero/zero and NaN for zero/zero. Having x/0 = 0 is worse than useless, it's mathematically wrong.

  56. Yes by Anonymous Coward · · Score: 0

    I'd like it to return an error, because it does not equal zero. It is undefined.

  57. I'm with you to some extent by wcrowe · · Score: 1

    I know that in a business setting, making x/0 = 0 would be okay. At least it has always been okay in my 30+ years of experience. But I think the problem lies at a very low level, that is, the CPU cannot divide something by zero. I am pretty sure this is why it is, universally, an error.

    --
    Proverbs 21:19
    1. Re:I'm with you to some extent by FranTaylor · · Score: 1

      I know that in a business setting, making x/0 = 0 would be okay

      because "in a business setting" nobody actually tests anything

    2. Re:I'm with you to some extent by mr_mischief · · Score: 1

      So let's see about that. Say you have $10,000 set assigned for an on-site training class and want to budget it against four employees, but none of them can make it to the class.

      What percentage did you spend on employee A's spot in the training class since there were zero students?

      10000/0 = ???

      Did you spend zero percent on that employee? Or does that $10000 stay in the training budget and not get spent (assuming you canceled early enough that you don't still owe the instructor)? Or did the instructor not get notified in time, and you spent the $10000, but zero employees benefit from it? Did the instructor not get notified because your training department didn't check for zero students attending?

      What's the return on investment of $2500 for which you get no return? Well, that's easy enough. It's zero, because 0/2500 is 0. But you didn't get the 2500 by dividing by zero. You got that by dividing by the expected 4. Zero was unexpected, or you wouldn't have scheduled the class in the first place.

      Canceling the class due to having zero students is an exceptional circumstance. Paying a traveling instructor to show up for a day and do nothing is an exceptional circumstance. There are multiple ways to handle exceptional circumstances: check beforehand or raise an exception message and handle it. You don't just ignore the exceptional circumstance because you end up doing stupid things with bad information.

      You don't suddenly have a zero cost per student class because nobody showed up and you spent $10000. You have just wasted ten grand if you still have to pay the instructor.

      tl;dr: 0 != 1 and 0 as a divisor is not an identity function.

      One DEFINITION of division is subtraction of the denominator from the numerator x times, where x is the result. You stop dividing when there's nothing left to divide out.

      Now let's try dividing some things by 2.


      6 / 2 = 1 + 4 / 2 = 2 + 2 / 2 = 2 + 1 = 3
      12 / 2 = 1 + 10 / 2 = 2 + 8 / 2 = 3 + 6 / 2 = 4 + 4 / 2 = 5 + 2 / 2 = 5 + 1 = 6

      by 3:
      9 / 3 = 1 + 6 / 3 = 2 + 3 / 3 = 3
      12 / 3 = 1 + 9 / 3 = 2 + 6 / 3 = 3 + 3 / 3 = 4

      by 0 :
      5 / 0 = 0 + 5 / 0 = 5 / 0
      3 / 0 = 0 + 3 / 0 3 / 0

      There's nothing to subtract there. You can't subtract zero from 5 enough times to get any number. Does that make 5/0 == 5 ? Does it make it 0? Does it make it approximately positive infinity? You can't simplify dividing by zero and have a meaningful integer result. (hint: you can subtract zero infinitely many times from 5 and still have 5.) IOW:

      5 / 0 = 0 + 5 / 0 = 0 + 5 / 0 = 0 + 5 / 0 = (the same thing ad infinitum) = 5 / 0

      Now there may be certain logical situations in which setting something to zero is the right thing to do in your exception handling code. Just letting everything be represented as if n/0 == 0 is not correct or desirable. It takes reasoning about how to handle the exceptional case.

    3. Re:I'm with you to some extent by wcrowe · · Score: 1

      That's not what I'm saying. When you have a number of critical jobs that have to be run, you don't want all of them held up because some idiot somewhere forgot to put in, for instance, the number of students, and now there is a divide by zero error that brings everything to a standstill. In this case, it is far better to take the chance of paying out $10,000 accidentally (something that will probably be caught by someone before it becomes a problem), than the chance of losing $10 million because some other critical job did not get executed at the right time.

      --
      Proverbs 21:19
    4. Re:I'm with you to some extent by david_thornley · · Score: 1

      Could you give an example of when x/0 can be safely treated as 0? It's not a matter of the CPU. People design and make CPUs to implement arithmetic (not necessarily entirely correctly; anybody remember that Pentium division bug that somebody found back in 1993.9999999974?). If there was a sound mathematical value for dividing by zero, we'd build it into our CPUs. In fact, IEEE floating point does have an answer that works well, but it's the farthest thing from 0.0.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    5. Re:I'm with you to some extent by Ihlosi · · Score: 1
      Could you give an example of when x/0 can be safely treated as 0?

      a) The program needs to process bursts incoming data quickly and timely, and it is known that only nonzero output values are valid. The program combs through received data later, when there is time.

      b) You need to feed an audio DAC or something, and outputting 0 will result in a barely noticable glitch, but missing several samples due to exception handling will produce a very noticable acoustic artefact.

    6. Re:I'm with you to some extent by ceoyoyo · · Score: 1

      There was a Slashdot story a couple of years ago about a study of fortune 500 financial spreadsheets. It turned out that errors were so prevalent in those spreadsheets that the financial decisions being made by those companies weren't a lot better than random.

    7. Re:I'm with you to some extent by wcrowe · · Score: 1

      Here's an example. Your company has contracts to sell diesel fuel to a couple of thousand trucking company customers, who need to know what your quoted price is going to be every day, so that they can dispatch their trucks. So there is a program that runs at 3:00am that calculates and sends out the quoted prices to these customers. Meanwhile, Susie Mushferbrains, a college intern, forgot to enter some minor data which is needed for a job that happens to run at 2:55am in the same job queue as the diesel fuel quotes program. So, at 2:55:13am there is a divide by zero error which holds up everything in the job queue, and nobody notices this until 8am the next morning. Because the diesel fuel quotes didn't go out, the various trucking company dispachers are routing their vehicles to your competitor's stores and you lose several million dollars that day in revenue.

      It would be better if the system would just plug in 0 and send out a warning rather than crash a program because, OMG! bad math!

      --
      Proverbs 21:19
    8. Re:I'm with you to some extent by mr_mischief · · Score: 1

      Don't let it be an error that brings everything to a standstill. Check for and handle the inputs appropriately.

    9. Re:I'm with you to some extent by wcrowe · · Score: 1

      I know, but you can't account for every person's actions and every variable.

      --
      Proverbs 21:19
    10. Re:I'm with you to some extent by mr_mischief · · Score: 1

      It doesn't have to be every variable. It just has to be the one used as a denominator.

    11. Re:I'm with you to some extent by david_thornley · · Score: 1

      If a divide-by-zero error in another program holds up vital production long enough to matter, you're doing it wrong. If you allow your critical production jobs to just get trashed or held up without anybody paying attention, you're doing it wrong. If Susie created a divide-by-zero error for something about the cost of diesel fuel, and you're selling it 20 cents below cost the next day, you're doing it wrong.

      In the worst-run shops I've ever been in, if it was an important production job and it failed, somebody found out about it. I never want to work at the shop you describe.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  58. Zero equals something. by Anonymous Coward · · Score: 0

    The only problem I see is that Zero (0) is something. It's possible you could get the community to agree on a specific failure value (-492687 as an example), but then you still have the issue of what defines a return for a div-by-zero attempt. So yes, divide-by-zero returns could be tested for and defined in some other manner, but the problem is what happens when existing code actually relies on the return value you've decided upon?

  59. Default should be to raise an exception by Anonymous Coward · · Score: 0

    There is no problem with having a default, as long as it corresponds to raising an exception.

    The right decision when encountering a division by zero depends on the numerator and the meaning of the division, i.e., whether it can be seen as a limit or not.

    > Does anyone want their div by zero errors to result in anything other than zero?

    Yes. Your proposal is actually one of the worst things you can do in general: only when the division by zero can be seen as a limit *and* the numerator goes to zero faster is this even to be contemplated. Even then... signed zeros.

    (All of this is well-known of course.)

    1. Re: Default should be to raise an exception by Anonymous Coward · · Score: 0

      I have seen it implemented that should a divide by zero occurr, in the error trapping routine, it sets the result to either MAXVALUE or NEGATIVEMINVALUE for that datatype.

    2. Re:Default should be to raise an exception by FranTaylor · · Score: 1

      There is no problem with having a default

      Sure there is! What happens when your program generates the default value? You have a BUG! Not just any old bug, but one that will be REALLY DIFFICULT to track down and REALLY HARD to fix.

  60. On Error by YuppieScum · · Score: 1

    Resume Next

    What could possibly go wrong?

    --
    This sig left unintentionally blank.
  61. Re:x/0 does not equal 0. by Anonymous Coward · · Score: 3, Insightful

    No, mathematically, division by zero is undefined.

    Only engineers think it's infinity!

  62. No by Verdatum · · Score: 1

    Does anyone want their div by zero errors to result in anything other than zero?

    Yes.

    No.

  63. ARM has it by Anonymous Coward · · Score: 0

    Zero is kind of the opposite of the actual correct value, which is infinity.
    Having a default is fine, *if* you can change the setting. In ARM processors, you have just that; you can set a flag on the processor telling it to raise/not raise a DbZ exception.

    1. Re:ARM has it by FranTaylor · · Score: 1

      Having a default is fine

      for creating really really horrible, impossible to find, bugs

    2. Re:ARM has it by Anonymous Coward · · Score: 0

      I meant that the default should be, of course, ro raise an exception/error, and if the user wants to mask that exception, that's his problem.
      I think you can also mask exceptions in x86 CPUs, not just ARM.

    3. Re:ARM has it by Anonymous Coward · · Score: 0

      ARMv8 unconditionally returns 0 for integer division by zero,

  64. Maybe by Anonymous Coward · · Score: 5, Funny

    Does anyone want their div by zero errors to result in anything other than zero?

    Yes.

    No.

    Maybe.

    1. Re:Maybe by Anonymous Coward · · Score: 3, Funny

      Does anyone want their div by zero errors to result in anything other than zero?

      Yes.

      No.

      Maybe.

      Maybe not.

    2. Re:Maybe by Anonymous Coward · · Score: 0

      Does anyone want their div by zero errors to result in anything other than zero?

      Yes.

      No.

      Maybe.

      Maybe not.

      Wrong!

    3. Re:Maybe by Anonymous Coward · · Score: 0

      Does anyone want their div by zero errors to result in anything other than zero?

      Yes.

      No.

      Maybe.

      Maybe not.

      Reply hazy, try again.

    4. Re:Maybe by Anonymous Coward · · Score: 5, Funny

      Does anyone want their div by zero errors to result in anything other than zero?

      Yes.

      No.

      Maybe.

      Maybe not.

      Wrong!

      Pineapple.

    5. Re:Maybe by Rasperin · · Score: 1

      Does anyone want their div by zero errors to result in anything other than zero?

      Yes.

      No.

      Maybe.

      Don't look in the box!

      --
      WTF Slashdot, why do I have to login 50 times to post?
    6. Re:Maybe by sconeu · · Score: 2

      Black holes are where God divided by zero.

      --
      General Relativity: Space-time tells matter where to go; Matter tells space-time what shape to be.
    7. Re: Maybe by Anonymous Coward · · Score: 0

      Nah, that would be quantum field theory (see renormalisation in your nearest QFT text).

    8. Re:Maybe by Archangel+Michael · · Score: 1

      SQRT(-1)

      --
      Agent K: A *person* is smart. People are dumb, stupid, panicky animals, and you know it.
    9. Re:Maybe by Anonymous Coward · · Score: 0

      It really depends.

    10. Re:Maybe by Anonymous Coward · · Score: 0

      NaN.

    11. Re:Maybe by AK+Marc · · Score: 1

      Aww, I was hoping for "I don't know" followed by "could you repeat the question"

    12. Re:Maybe by the+phantom · · Score: 1

      You're not the boss of me!

    13. Re:Maybe by Anonymous Coward · · Score: 0

      Does anyone want their div by zero errors to result in anything other than zero?

      Yes.

      No.

      Maybe.

      yesnaby

    14. Re:Maybe by penguinoid · · Score: 1

      Does anyone want their div by zero errors to result in anything other than zero?

      Yes.

      No.

      Maybe.

      Looks like the answer to that is undefined.

      --
      Don't waste your vote! Vote for whoever you want, unless you live in a swing state it won't matter anyways
    15. Re:Maybe by Anonymous Coward · · Score: 0

      Aye!

    16. Re:Maybe by 19thNervousBreakdown · · Score: 1

      Does anyone want their div by zero errors to result in anything other than zero?

      Yes.

      No.

      Maybe.

      Maybe not.

      Wrong!

      PHP!

      --
      <xml><I><am><so><damn>Web 2.0</damn></so></am></I></xml>
    17. Re:Maybe by Anonymous Coward · · Score: 0

      I don't know, can you repeat the question?

    18. Re:Maybe by scsirob · · Score: 1

      !PHP

      --
      To Terminate, or not to Terminate, that's the question - SCSIROB
    19. Re:Maybe by __aabppq7737 · · Score: 1

      Black holes are where God divided by zero.

      if anything reached the center of one, that is, in a finite amount of time

  65. Why stop there? by Anonymous Coward · · Score: 0

    Why not change ++ to result in incrementing by 100 instead of 1? What's the harm with that?

  66. doing it wrong by FranTaylor · · Score: 2

    Would there be any serious harm in allowing a system wide setting that said div by zero simply equals zero?

    What could possibly go wrong when you assert that infinity equals zero? Well, let's see, your logic errors will go undetected, for one. If you are dividing by zero YOU ARE DOING IT WRONG. You might as well just ignore bus errors as well. And while you are at it, just ignore if the disk is full and keep writing anyway. What could go wrong?

  67. I don't think you understand the definition by Thud457 · · Score: 5, Funny
    Division by zero - how many times does zero go into a number?

    100.0 / 0 = 3
    402350.32302 / 0 = 3
    pi / 0 = infinity
    1942 / 0 = 0
    194.3 / 0 = 0
    101 / 0 = 1
    1010 / 0 = 2
    200.02 / 0 = 3
    4004004 / 0 = 4

    Somebody please submit a RFP for this to C++17 standards committee.

    --

    the preceding comment is my own and in no way reflects the opinion of the Joint Chiefs of Staff

    1. Re:I don't think you understand the definition by Anonymous Coward · · Score: 1

      In which base?

    2. Re:I don't think you understand the definition by Anonymous Coward · · Score: 0

      This is actually a valid thing to do for a C++ or C compiler, you could send your patch to GCC and Clang right now!

      As per the standard "If the second operand of / or % is zero, the behavior is undefined.", so anything can happen.

    3. Re:I don't think you understand the definition by Anonymous Coward · · Score: 0

      All of them!

    4. Re: I don't think you understand the definition by Anonymous Coward · · Score: 0

      Also pls:
      e = pi = 3

      So busy! Need to save some time.

    5. Re:I don't think you understand the definition by Lord+Ender · · Score: 1

      I wouldn't be surprised if PHP already works this way.

      --
      A slashdotter who didn't build his own computer is like a Jedi who didn't build his own lightsaber.
    6. Re:I don't think you understand the definition by Dynedain · · Score: 1

      Oh so you want to use this language: http://xkcd.com/1537/

      --
      I'm out of my mind right now, but feel free to leave a message.....
    7. Re:I don't think you understand the definition by Anonymous Coward · · Score: 0

      Division by zero - how many times does zero go into a number?

      100.0 / 0 = 3

      402350.32302 / 0 = 3

      pi / 0 = infinity

      1942 / 0 = 0

      194.3 / 0 = 0

      101 / 0 = 1

      1010 / 0 = 2

      200.02 / 0 = 3

      4004004 / 0 = 4

      Somebody please submit a RFP for this to C++17 standards committee.

      Just convert to binary and remove the 0s.
      782 / 0 = 31
      1100001110 / 0 = 11111

    8. Re:I don't think you understand the definition by Anonymous Coward · · Score: 0

      You fail. It's actually "how many times a number is divided by 0." So here goes:

      100.0 / 0 = 0
      402350.32302 / 0 = 4
      pi / 0 = infinity
      1942 / 0 = 0
      194.3 / 0 = 0
      101 / 0 = 2
      1010 / 0 = 2
      200.02 / 0 = 1
      4004004 / 0 = 3

      Cheers!

  68. Making problem worse by Anonymous Coward · · Score: 0

    So then you would have to add to every instance of a potential divide-by-zero a check for zero result. And worse still you would have to try and differentiate that zero from other zeros. In any case a divide-by-zero produces infinity, and infinity is certainly not quite the same as zero. In short, this is an idiotic proposal.

  69. sometimes the correct answer is 1 by Anonymous Coward · · Score: 0

    as most people have said, the "correct" answer is almost always +/- infinity. However, the Limit as x goes to 0 of x/x is 1!

    1. Re:sometimes the correct answer is 1 by ledow · · Score: 1

      There is no correct answer. What you are doing is not just "undefined" but impossible.

      Even an infinite number of zeroes can't multiply out to be anything but zero.

      So if you can get the answers "zero", "one", and "infinity" - all within the space of a few seconds - for the same question, there is no "correct" answer.

      It's like asking what the square root of -1 is. There is no answer that's a valid number in any of the sets of real or integer numbers.

      Division is only defined for non-zero denominators. It's as simple as that. Because there is no possible answer for a zero denominator.

    2. Re:sometimes the correct answer is 1 by FranTaylor · · Score: 1

      just like zeno, you will never actually get anywhere with that answer

    3. Re:sometimes the correct answer is 1 by Darinbob · · Score: 1

      There is an answer, but it is not representable exactly except as a special value (NaN for floating point).
      So mathematically it is well defined (exept for 0/0), however in many programming languages it is explicitly stated that the results are undefined. What that means is that the implementer of the language is allowed to do whatever they want (because it's undefined).

      Also the math does break down when you divide by zero, so while it's not meaningless it does mean that you can't properly use these values. For example:
            "X/N * N == X" or "X/N * N/X == 1"
      These equations break down when N is 0

    4. Re:sometimes the correct answer is 1 by Darinbob · · Score: 1

      Sorry, not mathematically well defined, I goofed up there. If you plot the curve of the results from negative divisors to positive, then there is a discontinuity at zero.

  70. But that is wrong by Anonymous Coward · · Score: 0

    But x/0 does not equal zero. It is undefined and assuming it is always zero is actually wrong.

    I don't think you can stop it for the whole program, as the error might be thrown by the CPU itself.

    Instead of checking for division by zero, you need to figure out and stop how a zero is getting there in the first place. You have a bug somewhere else in your program. Find it.

  71. Another problem by Vyse+of+Arcadia · · Score: 1

    Aside from all the other issues that have already been posted, another problem is that different systems will have different defaults . Makes stuff just that much less portable.

  72. Re:x/0 does not equal 0. by Verdatum · · Score: 4, Insightful
    No, it does not equal infinity.

    The Limit as x aproaches 0+ of a/x = infinity.

    But the Limit as x approaches 0- of a/x = negative infinity.

    because this represents a jump-discontinuity, the value of a/0 is just plain undefined.

    This is like week-1 of high school precalc shit. Come on.

  73. PowerPC Did This by brian6504 · · Score: 1

    Those of us who wrote for PowerPC may recall the architecture returned 0 for integer division by 0. It's been done before and, in my opinion, was a good trade off between mathematical purity and pragmatism. The vast majority of the code I write follows the pattern result = (denominator != 0) ? (numerator / denominator) : 0.

    1. Re:PowerPC Did This by FranTaylor · · Score: 1

      in my opinion, was a good trade off between mathematical purity and pragmatism.

      Yeah let's skimp on a few transistors here and there, in exchange for making computers that give out wrong answers. Gosh those transistors are SO BIG and SO EXPENSIVE nowadays.

    2. Re:PowerPC Did This by Anonymous Coward · · Score: 0

      I can't think of a single situation where you would want something / 0 to equal 0.
      If you get to that, then your algorithm is fundamentally broken.
      And before you give me the "divide apples over 0 people" let me tell you: you have zero people.
      Don't divide the fucking apple.

    3. Re:PowerPC Did This by Darinbob · · Score: 1

      However if you use the "o" form ("divwo.") then divide by zero will set the OE condition bit. However in both cases this still means that it is the job of the compiler to do the checking. The snag is that some languages, like C, say that the result of divide by zero is undefined and so they may not bother checking either (undefined means that the language implementation can do whatever it likes).

    4. Re:PowerPC Did This by Your.Master · · Score: 1

      To be clear, I am in full agreement that there is no good reason to change a *default* to setting it to 0, and that letting just anything divided by 0 equal 0 is an insane default. You have to flip the question, "in what specialized circumstances would this ever be a good idea?".

      However, maybe my imagination is just super powerful, but I certainly can imagine situations where you want something / 0 equal to 0, so long as that something is also 0. Measurements of rates-of-change.

      Imagine one of the odometers with a needle that rotates around in an arc -- it always points to a value, usually 0. Like the odometer on most cars. Suppose it measures the average velocity of your trip. 0 km driven / 0 seconds driving -- measurement is 0. 0 bytes downloaded / 0 seconds downloading = downloading at 0 bps. If you put this into Calculus terms, these would be limits that converge to 0.

      You might prefer to phrase it as f(X, Y) = X/Y where Y!=0, 0 where X=Y=0, undefined otherwise. That's even how I'd implement it in software (I certainly wouldn't do something crazy like overload the division operator). But that's functionally the same thing as defining 0/0 as 0, for that particular context.

    5. Re:PowerPC Did This by myowntrueself · · Score: 1

      Those of us who wrote for PowerPC may recall the architecture returned 0 for integer division by 0. It's been done before and, in my opinion, was a good trade off between mathematical purity and pragmatism. The vast majority of the code I write follows the pattern result = (denominator != 0) ? (numerator / denominator) : 0.

      If x/0 = some constant, whatever that constant might be whether infinity, zero, 8 or whatever, you get this:

      x/0 = c = y/0 therefore x = y for all numbers.

      So all numbers are equal and mathematics completely breaks down.

      --
      In the free world the media isn't government run; the government is media run.
  74. Sighd by ledow · · Score: 5, Insightful

    You want to find out how many Euros in those Zimbabwean dollars you're keeping track of. The exchange rate fluctuates. The web-API you're using goes offline and returns zero, so you divide by zero. Whoops. How do you tell the difference between worthless numbers and just worthless currency?

    You want to draw an interlaced gif of some sort, so you do every nth line, then every n-1th line, as you get the interlaced lines and work down towards a full image with every row drawn. And then you cock up at the end, accidentally hit zero and you overwrite the first line thousands of times with garbage rather than spot the mistake.

    Zero is so completely the wrong answer, you don't even understand why. The actual real answer shouldn't even be the largest integer you can hold. And if it is, it could also be the smallest (i.e. largest negative). But actually it's none of them.

    Division by zero is NOT something that produces a number. It cannot happen. It cannot return zero (which is incredibly wrong), nor can it return any single other consistent constant. It should actually just error, which is why it does. It should produce something that's not a number (NaN). And it does exactly that.

    Divide by zero is like a null pointer. On the face of it is appears singularly useless. Why on earth would you want a pointer that you can't dereference? But it's there as an indicator. You cocked up. Majorly. If your maths is at all important at that point (a cell in a spreadsheet), then you're potentially losing billions of digits of accuracy.

    You can continue on blindly with your cockup quite easily. Any idiot can overload the divide operator to return zero when the denominator is zero. And you won't get any of those nasty errors. Errors which are indicative of an earlier error that you're just ignoring.

    There's a reason that, even back in the days of BASIC and very limited ROM space, you programmed in divide by zero as an error rather than just returning zero and documenting it. It's the same reason that you don't just "ignore" NULL pointer dereferences by saying "Oh, well, we won't call that function and just carry on from where we were then". Any idiot could make some kind of overload to allow that as well if they really wanted.

    The fact is that if you're dividing by zero you're doing something that's mathematically impossible. There is no amount of zeroes you can multiply to get anything other than zero. Not even if you multiply infinities of zeroes do you get anything other than zero. Hence division by zero of any non-zero integer is IMPOSSIBLE. It doesn't have an answer.

    And, like the square root of -1, if you just ignore it and pretend it exists you will run into all kinds of trouble. If you want to do something with it, in the same way that we use "i" to represent the square root of -1 to get lots of magical maths that actually works, use a language that recognises NaN and test against it.

    But I'll tell you now that it's quicker and easier to test if you're dividing by zero BEFORE you do the divide.

    1. Re:Sighd by Anonymous Coward · · Score: 0

      Hence division by zero of any non-zero integer is IMPOSSIBLE. It doesn't have an answer.

      If you 'divide' something into zero pieces, it simply ceases to exist.

    2. Re:Sighd by angel'o'sphere · · Score: 1

      Any idiot can overload the divide operator to return zero when the denominator is zero.
      You can not overload operators for native data types.

      Any idiot could make some kind of overload to allow that as well if they really wanted.
      No you can't. It always throws an exception. Which you can catch, but you can not continue behind the point where the exception was thrown, you can only continue where you cought it.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    3. Re:Sighd by Anonymous Coward · · Score: 0

      1) Then don't do that.

      2) if (x) x->f();

    4. Re:Sighd by Anonymous Coward · · Score: 0

      It's the same reason that you don't just "ignore" NULL pointer dereferences by saying "Oh, well, we won't call that function and just carry on from where we were then".

      Have you looked at Objective-C? It goes one step further and returns 0/false/null as the return value if you call a method on a null object.

    5. Re:Sighd by Anonymous Coward · · Score: 0

      Divide by zero is not "mathematically impossible". Go back reddit.

    6. Re:Sighd by Anonymous Coward · · Score: 0

      Very good response, but you went off track with the square root of -1. "i" is an actual number. It exists and that square root is a valid operation. It just isn't a Real number and is Imaginary. Those terrible naming conventions are misleading as "i" is a real number just not contained in the set of Real numbers.

      As a programmer, or someone doing math work, we don't regularly deal with complex numbers so we err on the side of caution and throw an error when an operation produces a complex number. This is what divide by zero should do, throw an error.

      Really, the rule is quite simple. No matter what operation you are doing, you either return the correct answer, or you throw an exception. The exception could be "Divide by 0 Exception" or it could be "Decided not to code for complex numbers Exception"

    7. Re:Sighd by Anonymous Coward · · Score: 0

      What? How does that make sense?

    8. Re:Sighd by james_gnz · · Score: 1

      If you 'divide' something into zero pieces, it simply ceases to exist.

      No, if you divide something into an infinite number of pieces, it becomes infinitesimal, which is infinitely close to ceasing to exist, but not quite there. There's no way to divide something into zero pieces. However you divide it, you're always going to have some pieces. You'd need it to already not exist before you tried dividing it into zero pieces.

      But if that were the case, it would be a different story, because there's an infinite number of ways of dividing nothing into zero pieces: You can put all of it in each piece, or you can put none of it in each piece, or, in general, for any number x, you can put x of it in each piece. The problem then, is which way you ought to do it. It might be that there is a particular way you ought to do it, and you don't know which way that is, or, on the other hand, it might not matter which way you do it, so long as you do it some way.

  75. Dpends on the program by ebcdic · · Score: 1

    If the worst that can happen is a wrong pixel in a computer game, then that's fine. But if I'm analysing data to be published in a scientific paper, dividing by zero means an error in my program, and I want to know about it and fix it. It doesn't really matter whether it gives a nice error message or a core dump, but it must be noticed.

    1. Re:Dpends on the program by FranTaylor · · Score: 1

      If the worst that can happen is a wrong pixel in a computer game, then that's fine.

      If the developer is assuming that 0/0 = 0 then there is going to be much worse problems than a few bad pixels

  76. Makes perfect sense by physicsphairy · · Score: 2

    2/0.1 = 20
    2/0.01 = 200
    2/0.00000001 = 200000000
    2/0.000000000000000000000000000000000000000000000001 = 0

    Exactly as you would expect!

    1. Re:Makes perfect sense by Anonymous Coward · · Score: 0

      Come to think of it, I think there may be a few number systems that use special values for 'infinity' and let you get that as a result. It has some pretty weird semantics, though.

    2. Re:Makes perfect sense by Anonymous Coward · · Score: 0

      If you programmed this, it's your fault. When working on a system you should know the limits of your system. It got rounded because the system you're working on can't process that amount of decimal places. Float vs Double, but beyond that, you are stupid.

  77. Re:Divide by zero is NOT zero. It is an error by Anonymous Coward · · Score: 0

    Exactly, and if it was not an error, I can see 3/0 = inifinity, or very worst case 3/0 = 3 (you're not dividing after all) but never 0

  78. So incredibly stupid by Anonymous Coward · · Score: 0

    Not only is CodeInspired a complete moron for asking such a stupid question, but Timothy is also completely stupid for posting it. Something this idiotic does not deserve to be posted. It's not a good idea. It's not even a sorta, kinda, maybe a little bit okay idea. It is an absolutely, completely, 100% moronic idea. You should both be ashamed of yourselves.

  79. Ugh. by Anonymous Coward · · Score: 0

    Let me guess. You secure credit card data with your programming.

  80. Hell No! by RedLeg · · Score: 1

    First, division by zero is undefined in mathematics.

    You MUST throw an exception, and handle it appropriately, or you are headed for bug hell.... google the plight of the USS Yorktown and a zero-divide unhandled exception if you need a real world lesson.

    Second, IF you were to entertain the thought of actually returning a value, zero is the wrong value. (set mode=mathematician)

    The limit of 1/x as x -> 0 is infinity if I remember correctly..... It has been 35 years since that particular class.....

    1. Re:Hell No! by Anonymous Coward · · Score: 0

      > The limit of 1/x as x -> 0 is infinity if I remember correctly..... It has been 35 years since that particular class.....

      No. You get 1/x -> oo as x -> 0. But the "-> oo" is syntax and not a statement of a limit.
      You will not get a limit since one side goes big and positive while the other goes big and
      negative.

      If you want a limit value, you need to decide whether you want to approach zero from the
      left or from the right. The limit will be -oo or +oo, this time as values in the extended reals.
      (And with an extended definition of limits.)

    2. Re:Hell No! by petermgreen · · Score: 1

      The limit of 1/x as x -> 0 is infinity if I remember correctly.

      Only if you approach from the positive side. If you approach it from the negative side then you get a limit of minus infinity.

      IEEE 754 gets arround this by having positive and negative zero but that often seems like a cure worse than the disease.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    3. Re:Hell No! by gnu-sucks · · Score: 1

      Come to think of it though, if you are working in uint space (that is, unsigned ints), than you *can't* have approached from below zero.

      And if you were for some reason working with unsigned ints that were always multiplied by -1 than I think you'd still be ok with -1 * inf as your result.

      Just so we're clear: this is stupidity -- the algorithm is not returning useful data and it will only mess up everything down the line. Sanitize before you divide, handle divide by zero as an error or a special case.

    4. Re:Hell No! by petermgreen · · Score: 1

      Come to think of it though, if you are working in uint space (that is, unsigned ints), than you *can't* have approached from below zero.

      but then if you are working in integer space (signed or unsigned) then you can't really approach at all.for the idea of "approach" to make sense you need to be working in a space (e.g. the rational numbers) where you can get arbiterally close to something without getting there.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
  81. Infinity... or maybe not by TeknoHog · · Score: 1

    In measure theory, a positive number divided by zero is defined to be infinity, and there's likewise a negative infinity. OTOH, in complex analysis there's a single point at infinity. I'm sure there are other well-defined notions of infinity, and you can dig deeper into things like compactification. However, none of the definitions of infinity is equal to zero, for the obvious reason that 0 times 0 is still 0. Also, you need rules such as infinity times zero being undefined, so by having a numerical value for infinity (like NaN) would just push the problem further. The unfortunate fact is that the set of real numbers is not closed with respect to division, and you have to deal with it one way or another, rather than hiding the problem.

    --
    Escher was the first MC and Giger invented the HR department.
  82. Infinity or an error by Anonymous Coward · · Score: 0

    In my world, x/0 is usually infinity. This almost always the case in Calculus. An exception being l'hopital's rule where it can be a number.

    Normally, something is wrong either in code or with my data if I encounter an unexpected division by 0. I would rather catch it and log an error than continue my computations with an incorrect 0 value.

    Even in basic algebra, it isn't computed to 0. Graph out y = 1/x. At x = 0 it if both negative and positive infinity.

  83. No by pwnyxpress · · Score: 1

    I don't want the default to be that, but if you write a function that way it better be clearly documented and adhere to the following statement.

    f is the function containing /0 returns 0 iff f(x) does not contain 0.

    This must also be communicated clearly and concisely to anyone using the function.

  84. After 20 years of programming...Really? by Anonymous Coward · · Score: 0

    How many of those years were in elementary school?

    Do you have any background whatsoever in CS or Mathematics?

    When I see a divide by zero, it's a damn exception; alternatively it's NaN.

    Just off hand I can't fathom why you would want the answer to be Zero.

  85. Legacy code by Anonymous Coward · · Score: 0

    Legacy code for a lot of programs will cause problems.

    Honestly, I would create a new symbol that would count as a number, just as "i" is a number - the Square root of -1.

    Call it NEL. Divide anything by 0 and you get NEL. The use of any and all other math operations on NEL give you NEL (NEL+1=NEL, NEL/NEL = NEL, etc. etc. etc. )

    Now you have a mathematical symbol for - shall we call it 'bad math' that does not result in an error. Probably useful in a lot of other cases as well - just as "0" itself was a useful mathematical concept.

    Maybe we could expropriate a 0 inside another 0 for the symbol of NEL.

    1. Re:Legacy code by TapeCutter · · Score: 1

      That's (sort of) what NaN (not a number) is for in C/C++, also "NULL" is traditionally used to represent a missing/undefined value in a database.

      --
      And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
  86. We should just get rid of all errors by Khashishi · · Score: 1

    Any time there's an error, just skip it and go to the next instruction.
    Bam. No more errors.

  87. Pi is exactly 3! by tehlinux · · Score: 1

    Is this a real question or are they just screwing with us?!

    --
    Most linux users don't know this, but the man pages were named after Chuck Norris. Chuck Norris fsck'ing hates noobs!
  88. Is /. getting stupider? by Kjella · · Score: 2

    Let's say I have have product sales like 4,6,0,5 and want % changes:

    6/4-1 = 0.5 = +50% ok
    0/6-1 = -1 = -100% ok
    5/0-1 = -1 = -100% epic fail

    Though I really wish you could get NULL when doing a divide by 0 in a database instead of an error.

    --
    Live today, because you never know what tomorrow brings
    1. Re:Is /. getting stupider? by Anonymous Coward · · Score: 0

      You can.

      CASE WHEN x <> 0 THEN y / x END

    2. Re:Is /. getting stupider? by Kjella · · Score: 1

      You can.

      CASE WHEN x 0 THEN y / x END

      Yes that's the workaround but often "x" is actually SUM(something something) that you have to duplicate unless you can use a CTE, then the contents of x changes and you end up with "CASE WHEN x 0 THEN y / x' END" where x and x' aren't actually the same thing and suddenly x' is 0 when x is not.

      The same way I think SQL could use an alternative equality/inequality operator that treats NULL as a value, in certain cases a = b OR (a IS NULL and b IS NULL) is exactly what I'm trying to do and ISNULL(a,x) = ISNULL(b,x) where x is some value that can't happen otherwise is terrible for indexes and such. Not in general but occasionally a $= b or a @= b or a %= b or whatever operator would be great.

      --
      Live today, because you never know what tomorrow brings
    3. Re:Is /. getting stupider? by Anonymous Coward · · Score: 0

      Matlab will helpfully return NaN, which seems at least as good as throwing an exception.

  89. Use a language that doesn't require you to check by Anonymous Coward · · Score: 0

    With Java, your program will fault when encountering division by zero. Even with C++ it should be possible to trap this exception.

    If it happens, _you_ the programmer fucked up the logic of your program. However, if you're trying to prevent / discover this in every single division throughout your program, you're doing something wrong.

    Think of your error handling code as risk as well as any other code. Does it make sense to make code for everything that might happen, or does it make sense to just give up on some level and move on?

    After 20 years, you're experiencing fatigue. If you haven't realized your code will never be perfect, and it will be replaced as soon as you're gone (hopefully), then maybe it's time to realize this and simplify your life, and code.

  90. Thank you by Anonymous Coward · · Score: 0

    That comment made me laugh so much! "I do not like the result of a division by zero! Let's change maths!"

    Awesome!

  91. Was slashdot hacked today? by vivaoporto · · Score: 4, Insightful
    Because it is not, and it would cause code like to fail for a = 1, b = 2 and c = 0:

    if ((a/c) == (b/c)) {
    // It is safe to assume that a == b
    }

    In a code as simple as that it is easy to spot but in more complex code this simple verification may be done in more steps or split in many different operations like:

    speed1 = distance1 / time;
    speed2 = distance2 / time;
    some_function(speed1, speed2);

    where some_function(speed1, speed2), built by other team has:

    if (speed1 == speed2) {
    // distance was the same, do something accordingly
    }

    Now, how this question was accepted as legitimate in an advanced forum like this it is amazing. Rock bottom.

    1. Re:Was slashdot hacked today? by Anonymous Coward · · Score: 0

      Because it is not, and it would cause code like to fail for a = 1, b = 2 and c = 0:

      if ((a/c) == (b/c)) { // It is safe to assume that a == b

      }

      Well, that's just a bad method for testing for equality. You'd run into the same problem (but no divide by zero error) with this slightly different but logically similar version:

      if ((c/a) == (c/b))

    2. Re:Was slashdot hacked today? by mugurel · · Score: 1

      In your example, some_function(speed1, speed2) is making assumptions about a variable outside its scope (time). That's not good programming either.

    3. Re:Was slashdot hacked today? by Anonymous Coward · · Score: 0

      I can think of two realistic cases that look like that right off the bat. One is unit conversions, where you're normalizing each side (this is just a condensed version).

      Another is to drop the least significant bits from the comparison, when two values are bit-packed together (eg. for lock-free atomic sets of paired values).

    4. Re:Was slashdot hacked today? by Anonymous Coward · · Score: 0

      Advanced? What gave you that idea?

    5. Re:Was slashdot hacked today? by Anonymous Coward · · Score: 0

      Because it is not, and it would cause code like to fail for a = 1, b = 2 and c = 0:

      if ((a/c) == (b/c)) { // It is safe to assume that a == b

      }

      That's also the case for a=1, b=2, c=3, regardless of your rules for zero, as long as you use integer division. Therefore, languages should raise an exception when performing an integer division where the result can't be represented as an integer.

  92. Eugh by Dunbal · · Score: 4, Insightful

    After 20 years of programming, I've decided I'm tired of checking for div by zero.

    I am amazed that someone can persist in a career for 20 years without a clue as to what they are doing. If you are getting divide by zero errors there is something wrong with your logic. Don't blame the computer and certainly don't try to outsmart the computer which is trying to help you by pointing this out. Div by zero errors aren't something you should gloss over, they're something that should make you sit down and come up with an algorithm that actually does what you thought it was supposed to do.

    --
    Seven puppies were harmed during the making of this post.
    1. Re:Eugh by 140Mandak262Jamuna · · Score: 1

      Amazed he (or she) has not discovered how to set IEEE exception handlers. The only platform that would not let me set the handlers is DEC-Alpha. Technically it would let me set it at compile time, but at run time it will blithely ignore it and invoke the default exception handler. Default is crash. At some point we stopped doing purify, boundschecker etc. If it does not crash in DEC-Alpha, it has no memory violations!

      --
      sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
    2. Re:Eugh by phorm · · Score: 1

      Indeed. Now there might not be a problem with a "default setting" in his particular function or application, but applying to a language in general in pretty dumb.
      "Hey, I've never needed to sanity check this so let's change it and potentially f*** things up for a bunch of people" sounds like a greeeeeat idea. While we're at it let's skip bounds-checking entirely, and null-pointer checks.

    3. Re:Eugh by Anonymous Coward · · Score: 0

      i was about to post with this same sentiment. this person is clearly not a computer scientist, nor software engineer, nor really a professional programmer. if anything, they are a code monkey at best, with all the probably shit flinging that likely entails. apologies to the actual monkeys.

    4. Re:Eugh by Anonymous Coward · · Score: 0

      He probably divided by zero to figure out the number of years in his career.

  93. Dividing by zero doesn't result in zero by Anonymous Coward · · Score: 0

    No.

    lim 1 / x =
    x 0

  94. Dividing by a void by Dutchmaan · · Score: 1

    Dividing by zero means your dividing by nothing, which is a logic error. It doesn't cause the thing your not dividing to become nothing.

  95. And 2+2 = 5 by PPH · · Score: 3, Funny

    ... for extremely large values of 2.

    While you are making changes ....

    --
    Have gnu, will travel.
    1. Re:And 2+2 = 5 by turning+in+circles · · Score: 1

      I once wrote an English paper in which I suggested pi be replaced by 3 to make the math easier. I was going for satire. The guy posting today is going for . . .

      --
      Might as well face it I'm addicted to data.
    2. Re:And 2+2 = 5 by Anonymous Coward · · Score: 0

      Sorry, but for extremely large values of 2,
      2+2=6.

    3. Re:And 2+2 = 5 by redshirt · · Score: 1

      Where are mod points when I need them?

  96. Language extensions by Anonymous Coward · · Score: 0

    A number of languages have some sort of "if A is null use B, else use A". For example in C# you can do "myVar = subject ?? defaultValue". Perhaps extending that syntax to include divide by zero? so, "myVar == a/b ?? 0". Or, for a more explicit exception handling syntax, something like myVar == a/b ?? DivideByZeroException 0"

    Then at the OS and code execution level, the divide by zero still throws an exception, but at the code level the exception is handled in a compact manner.

    Of note, C# 6.0 has a number of language extensions for handling null reference, such as "myVar = value?.Substring(0, Math.Min(value.Length, length));" so adding another one for DivideByZero isn't so shocking.

  97. I returned a big number. by dplong · · Score: 1

    I implemented a floating-point package years ago on a system whose integer CPU did not support floating point. I returned as close to infinity as I could--the largest floating-point number. Mathematically incorrect, but for its purpose, this worked just fine.

  98. You, Sir, are a fool by idji · · Score: 2

    You will have many horrible consequences.
    You have no idea what your code will produce.
    You will never know that your code actually works.
    As you spend a VAST amount of time debugging weird stuff, you will eventually realize it would be better if the program crashed when the error happened.

    Example from yesterday. A web-based graphing package had a field "Number of minor ticks per tick". I selected 0 and pressed ENTER. The webserver crashed with a division by zero error.
    If that software had FOOLISHLY decided to replace a division by zero with 0, then it would have gone into an infinite loop drawing the graph when it calculated the
    tickspacing to be zero...

    Example from today. I was configuring a call to a SOAP service, which was receiving an error from the Server "Division by Zero". It turned out that the error was that I had an HTTP header with no value.
    Division by Zero is an error TO BE IGNORED AT YOUR PERIL.
    Yes, both pieces of software had sloppy coding, but they both crashed, which helped me continue.

    1. Re:You, Sir, are a fool by Capt.Albatross · · Score: 1

      You will have many horrible consequences.

      You have no idea what your code will produce.

      You will never know that your code actually works.

      As you spend a VAST amount of time debugging weird stuff, you will eventually realize it would be better if the program crashed when the error happened.

      This person is claiming twenty years of programming experience, and if so, then all but the last of these things have already come to pass.

      Sadly, it is not hard to believe that this person not only has 20 years experience, but in a professional capacity, and ditto for everyone who is supporting this idea. This is why there is so much bad software around: too much of it is written by people who do not really understand either what their own code is doing or what they are trying to do with their code.

  99. Dear Slashdot, math is hard by sideslash · · Score: 3, Funny

    "Can't I just be a programmer and not understand math?"

    1. Re:Dear Slashdot, math is hard by Anonymous Coward · · Score: 0

      Apparently, yes.

    2. Re:Dear Slashdot, math is hard by Anonymous Coward · · Score: 0

      99% of the coding in 99% of programming jobs is C.R.U.D. interfaces which, really, need little to no understanding of math.

  100. maybe... by idji · · Score: 1

    after 20 years of programming you should also be tired of checking for SQL injects, or out-of-range errors, but you had better not stop checking!

    1. Re:maybe... by FranTaylor · · Score: 1

      "I'm tired of entering SQL statement after SQL statement. How about we introduce a semicolon operator that lets me concatenate many SQL statements into one! Hey what could POSSIBLY go wrong?"

  101. Paraphrasing the OP by Anonymous Coward · · Score: 0

    "My code is shit, I keep getting div/0 errors. What kind of hack can I put in place so that I can continue to produce shit code without getting these errors?"

  102. Video explaination by Verdatum · · Score: 1
    This video does a decent job of explaining the problem: Numberphile: The problem with zero" It tries to address the very question that OP is asking.

    Division by zero isn't equal to zero. It isn't equal to positive infinity. It isn't equal to negative infinity. the value of any number divided by zero (including 0) is that it does not exist. After all, doesn't any number divided by itself equal to one? So shouldn't 0/0 = 1? No, because you can't divide by zero. The proper way for a computer to respond to an attempt to divide by zero is, "I have absolutely no idea what's going on here. I speak math, and you just asked me to do something that is outside of the language of math. I am going to either crash so I don't do anything stupid, return a reserved value that explicitly indicates that the answer does not exist, or jump out a level, throwing a runtime exception (as appropriate for the given language), and let YOU tell me what to do now. It has to be this way because there is never a single answer that always holds true about what a computer should do when encountering this.

    This should be hammered into you first in precalc, and again in any first-semester intro to computer science course, and again in discrete structures, and again in a computer hardware course. This is the reason for a lot of the hostility for asking this question.

    1. Re:Video explaination by Darinbob · · Score: 1

      There's a related but similar problem that many programmers overlook because they never studied numerical analysis (which should be required by all CS majors in my view). The problem is that accuracy is not infinite. So while they may understand that division by 0 is bad, they may not realize that division by a really tiny number may also be bad. Often programmers will take a formula and try to implement it verbatim and then end up with a huge loss in precision that could be avoiding by reordering the operations. They think that if things aren't working with "float" that they should just use "double" or "long double".

    2. Re:Video explaination by david_thornley · · Score: 1

      In some circumstances, the value of expression1 / expression2 is defined even if expression1 and expression2 are zero. You can make an argument that n/n is always 1, and 2n/n is always 2, even when n == 0. (You'll run into L'Hopital's rule in calculus, and this does define some expressions with 0/0.) This means that, if a straight 0/0 had a value, it would have to be 1 and 2, among infinitely many others.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    3. Re:Video explaination by Dixie_Flatline · · Score: 1

      Ugh.

      Look, in mathematics, dividing by zero makes no sense and that's fine. But I'm not working in the realm of pure math, I'm doing some actual work in a little universe of my own construction here. I don't need the value to be some sort of infinity. The value is undefined on our computers because we say so.

      I'm a games programmer, and there are plenty of situations where we might accidentally end up with 0 as the denominator, and it would have no bad effects at all to treat that as a zero. In most cases, that's actually the expected result. That is, I end up writing ternaries like:

      float foo = x != 0 ? y / x : 0;

      foo will be zero if x is zero, otherwise it's some fraction. Why is x zero? I don't know, maybe it was a countdown timer, or I'm just trying to find some fractional interpolation along some curve or something. NaN is a MEANINGLESS answer. Zero is the only answer I want out of this equation when x is zero.

      Your understanding of math is correct for our normal every day situation, but in broad strokes, you're wrong. I can easily define a new mathematical system where division by 0 is both allowed and defined. Algebra is very flexible this way. That's why when you add 25 hours to 2pm, you end up at 3pm the next day, and not 27pm. We've defined math in this daytime context to wrap around. There's no such thing as 27-o-clock. In this algebraic system, 2 + 25 != 27.

      So what this programmer is asking isn't about whether or not dividing by zero in the purest mathematical sense is correct, they're asking whether or not it makes sense to have an alternate system where division by zero just gives you zero, since zero is almost always the answer that they (and that I) want.

  103. Nope by Anonymous Coward · · Score: 0

    Why not treat null numbers as 0? Or "" as a null string or vice versa? Or do 20 place decimal calculations without considering the concepts of accuracy and arbitrary precision?

    A div by 0 is a fuckup. Unless you considered its effects in a specific context and deemed it to be OK, in which case you already wrote the code to handle it.

  104. Not for me, no. by Anonymous Coward · · Score: 0

    I actually want to know when there is a pathological / exceptional condition.
    As it happens, I run into this problem very seldom, I am not troubled to check for it, and I handle the situation as needed.

    Also a system-wide setting just seems like a bad idea. Use a per-process or per-thread setting if you must, if what you're looking for is even possible.

  105. No by viperidaenz · · Score: 1

    Anything divided by zero is not a number.

    If you end up with a div zero, you should have handled the case in a special way.
    In some cases it can be correct to treat the result as zero, in other cases the result should be infinite. Sometimes it should be 1.

  106. On a similar note by Anonymous Coward · · Score: 0

    I've been shopping at the supermarket for 20 years, and sometimes they don't have what I want, and I have to do something else. I tried to buy bread the other day, and the clerk told me they were out. Whenever they're out of bread, I substitute potatoes. Why can't the clerk just silently give everyone in the world potatoes instead of telling people they're out? I'm really tired of having to handle this special case of being out of bread and then get potatoes. Does anyone else in the world want to be told they're out of bread when a store is out of bread? Doesn't everyone just want to get potatoes instead?

  107. ON ERROR RESUME NEXT by Anonymous Coward · · Score: 1

    Is Dice trying to get the answers to tech interview questions now? If you really want to silently ignore all errors, no matter how badly your application's logic has gone off the rails and no matter how crazy your application might act due to not knowing what the hell is going on, you can code in VB and add "ON ERROR RESUME NEXT" at the top.

    Suffice it to say, it's generally a bad idea to have the program continue on even when it should know that it no longer knows what it's doing. But hey, as long as it only erases your bank account or whatever, you can code any way you want.

    As they say, garbage in, garbage out. If you silently ignore garbage coming in, guess what you get out of the program?

  108. Re:x/0 does not equal 0. by RackinFrackin · · Score: 5, Insightful

    Dividing any other number than zero by zero is well defined as infinity or minus infinity.

    We need a -1 Wrong mod for just this sort of post.

  109. Re:x/0 does not equal 0. by blue+trane · · Score: 1, Offtopic

    Math is not expressive enough to handle the real world, since division by zero can occur without causing a problem. Example: you want to divide apples among people. You have one apple and two people, each person gets half an apple. You have one apple and no people, no one gets the apple. In the real world there is no problem with this reasoning, it's only that math fails to handle it so you have to include extra code to make it come out. In a real life situation, you need no extra error-handling because there is no error. In conclusion, math fails to express the natural world.

  110. on error resume next by amoeba1911 · · Score: 1

    What you're asking for is equivalent to the "on error resume next" feature of Visual Basic.

    If you just barely know how to operate a fork-lift, you will not get a job operating a fork-lift.
    If you just barely know how to fly an airplane, you will not get a job flying an airplane.
    ... but if you just barely know how to program computers, you'll get a job programming computers just fine because the management can't tell the difference between a true programmer and a coder who just hits keys on the keyboard until something looks like it does what it's supposed to do.

    If you get a divide-by-zero error, it's not because the computer made a mistake, it's because you made a mistake.

  111. Re:x/0 does not equal 0. by mark-t · · Score: 3, Insightful

    For definitions of "well-defined" that selectively ignore the definitions that mathematicians use, perhaps.

  112. When Chuck Norris by Anonymous Coward · · Score: 0

    divides by zero the numerator no longer ever existed.

  113. Really ? by Anonymous Coward · · Score: 0

    How the hell does that make the Slashdot frontpage ?

    This is one of the most stupid questions I heard in my entire life.

  114. @ OP.... by naturaverl · · Score: 1

    You, sir, are an idiot.

  115. Re:x/0 does not equal 0. by FranTaylor · · Score: 2

    You have one apple and no people, no one gets the apple. In the real world there is no problem with this reasoning,

    In conclusion, math fails to express the natural world.

    Umm, math is not failing to express the natural world, NOT AT ALL. It is the IMPLEMENTATION of the math that fails to express. Mathematics is totally comfortable with the idea of infinity. Integer arithmetic IS NOT.

    FAIL

  116. Re:x/0 does not equal 0. by deKernel · · Score: 1

    Actually scientist think it infinity.....engineers will do if{} else {} to meet the specification....coders just catch the exceptions and return "unable to process".

  117. Sounds like bugs by The+MAZZTer · · Score: 5, Funny

    caused by dividing by zero returning zero.

  118. Not really by davidwr · · Score: 1

    In a business setting, x/0 does not always equal zero.

    Sure, there are cases where it does, there are many cases where it does not.

    I'd much rather the system throw an exception so I can handle it as needed for my specific task.

    Now, what I would like, and what some environments provide, is a way for me to trap an exception and handle it myself. I've never had to trap "/0" but I assume it could be done if my program was suitably privileged.

    --
    Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
  119. Floating point by Jamu · · Score: 1

    This might make more sense if you're using floating-point, where zero might represent the range -epsilon/2 to epsilon/2. In this case it might make sense to return a value on the assumption that a zero value isn't possible, and any value would be correct, although wildly imprecise.

    --
    Who ordered that?
    1. Re:Floating point by tristes_tigres · · Score: 4, Interesting

      Oh my god, this whole discussion is so misguided it hurts my eyes to look at. Why don't you people go educate yourself about floating-point arithmetics? IEEE754 standard was designed by top-notch numerical expert and YOU IGNORE IT AT YOUR AND YOUR USERS' PERIL.

      And yeah, division of nonzero by +zero must give Inf, and there are actual useful numerical algorithms that make use of that.

    2. Re: Floating point by Anonymous Coward · · Score: 0

      True, but you would probably want to inform the user of the wild imprecision - which requires detection of said divide by zero.

      eg it's not uncommon for numerical optimisers to return both a solution and a code telling you if said solution is worth the bits it's written on.

    3. Re:Floating point by Chris+Mattern · · Score: 2

      Well, you're fighting against the people whose opinion is, "God, I just want my program to compile and run so I can go home! Who cares if it gives stupidly incorrect answers!"

    4. Re:Floating point by tristes_tigres · · Score: 1

      Bingo!

      And if those people are writing code for twitter and facebook, I have no objection. But over yonder someone claims that he wrote a flight control software. Now that's scary thought (even if it is for a hobby drone)

    5. Re:Floating point by Anonymous Coward · · Score: 0

      What would you do with INF as an answer, when used using time as a something you need to limit your actions with? It's 0, you have 0 time when you your calculations are something/time and time is 0. In fact even if it wasn't time, still what the hell would the answer INF help in any calculations where you try to control something in the physical world?

    6. Re:Floating point by tristes_tigres · · Score: 1

      And if it's weight of a piece of cheese, you go to your mommy for another one.

      Slashdot these days, it's amazing. It's like perpetual September

  120. Can I have case insensitivity by goldcd · · Score: 1

    and typing of variables then?

    I mean I quite like them in their place, like commenting and indenting - they seem nice to have and something you *should* do.
    But... well we seem to have taken it a bit far. We let compiler/OS handle so much for us and yet we seem hell-bent on preserving this 'nickety' little annoyances.

  121. Re:x/0 does not equal 0. by brantondaveperson · · Score: 1

    Sorry no. The error is in your answer.

    Dividing any other number than zero by zero is well defined as infinity or minus infinity.

    See. It can't be defined as one of two different things, especially since neither of those things are a number. Except that you're probably joking, right?

  122. Vague question by g01d4 · · Score: 2
    If you're programming float then what's wrong w/the IEEE standard (assuming it's supported in your implementation)? From Wikipedia

    The IEEE floating-point standard, supported by almost all modern floating-point units, specifies that every floating point arithmetic operation, including division by zero, has a well-defined result.

    Defining it to zero only makes sense where zero is also an error in the numerator, and/or zero is not a valid result in your problem domain.

    1. Re:Vague question by gweihir · · Score: 1

      IEEE754 defines it to be +inf or -inf (depending on the sign of what you divided) and you cannot actually use it as input for further calculations and rightfully so. On the mathematical side, +/-inf is a NaN that resulted form the special case of having divided by zero.

      So, not only is the proposal of the OP terminally stupid, he did not even do basic research into the question.

      --
      Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
  123. Re:Divide by zero is NOT zero. It is an error by Anonymous Coward · · Score: 0

    3/0 = infinity *could* be true in certain circumstances (math involving infinity is wonky, though).
    3/0 = 3 can't be true in *any* circumstance, because that would also mean that 0=1.

  124. Can you repeat the question? by Anonymous Coward · · Score: 0

    Does anyone want their div by zero errors to result in anything other than zero?

    Yes.

    No.

    Maybe.

    Can you repeat the question?

  125. Absolutely! I usually want "infinity" by Anonymous Coward · · Score: 0

    There's a reason the IEEE floating-point spec defines non-zero/0 to be infinity and 0/0 to be NaN.

    For non-zero/0, infinity is the "correct" answer and anything else will give strange results.

    For 0/0, the "undefined" case, arguments can be made for any value depending on the situation. Often, there's a value that makes the result of a large computation continuous. When computing the sinc(x) = sin(x)/x function popular in signal processing, sinc(0) = 1 is correct.

    But the ALU computing 0/0 doesn't know what the right value is.

  126. Classic: you are doing it wrong by vux984 · · Score: 1

    If you are dividing by zero in the first place you are doing it wrong. You should never be throwing divide by zero errors; because doing so means you've already failed.

    You should know you have a valid denominator before you attempt the division.

    In other words, ensure your denominator is non-zero before you divide rather than trapping divide by zero errors, because if your code is asking a computer to divide by zero you've already fucked up somewhere else.

    1. Re:Classic: you are doing it wrong by gweihir · · Score: 1

      Indeed. The divide-by-zero error message is merely an additional safety net, the error happened some time before that when the divisor was determined.

      Or let me restate that in language the OP may be able to understand: If you divide by zero then _you_ have fucked up!

      --
      Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
  127. Already exists - TI DSP by Anonymous Coward · · Score: 0

    IIRC we use a Texas Instruments DSP in some of our products that returns zero on divide by zero.

    Seems to work fine, except that it trips you up when porting from the DSP platform to e.g. a PC platform where the divide-by-zero behavior is different..

  128. Successes/Opportunities by Mycroft-X · · Score: 1

    I work in performance management and often we do a successes/opportunities calculation. Often when there are zero opportunities, that is a good thing ("Number of server crashes resolved without user impact"). We do not want 0/0 to evaluate to a 0% success rate, that should default to a 100% success rate because there were no failures to unsuccessfully respond to.

    1. Re:Successes/Opportunities by ezakimak · · Score: 1

      There is no rate if there is no interval.

  129. Embarrassed to have been a programmer for 20 years by Anonymous Coward · · Score: 0

    because apparently people who have been programmers for 20 years don't know why a number divided by 0 isn't 0

  130. On Error Resume Next by Anonymous Coward · · Score: 0

    To get this functionality all you have to do is switch to using old school Visual Basic (not VB.Net) and include:
        ON ERROR RESUME NEXT
    In all your files. You will never be told when you have a problem ever again. Even better this applies to more then just divide by zero, it work for null pointer exception, integer overflow, ignore all the errors!

  131. Sort, Quicksort, Heapsort by michael_rendier · · Score: 1

    multiplication is a more complex addition...division, i'm told by the internet, is a more complex form of subtraction. we subtract the divisor from the dividend and continue until we reach a point that no whole divisors appear, and that is our remainder. personally, I kinda find this moronic. at divide by 0, you subtract zero from the dividend, and get an answer...a unity...the same number split into 0 pieces. The undefined in the computer (so says teh intertubes) is that this complicated subtraction is continued ad infinitum until exception and halting...for undefined. i also believe that the type of zero you are talking about is VERY important, as like infinity, zero is not a number but a concept...and given humanity's provincial "never being wrong" attitude...i ask this...could there be more than one type of zero? In Newtonian gravity, divide by zero when the distance between two objects becomes zero results in "undefined". Personally, i look at this event in my head and realize that if the two objects are 0 distance apart, you could easily (depending on composition and actual mass) you would no longer have two objects...no distance between centers of mass, since you only now have one mass. This zero specifically refers to the distance between two bodies of mass moving towards each other...wouldn't the equation change once there is only one body, no distance to travel...just a unified single object possibly in motion? so this is going to get a little into sort, quicksort, and heapsort arguement. what kind of divisions would result in actual numbers, should we simply change how we divide? how about removing single units into a number of piles equal to the divisor and the remainder is still the same? In this scenario though, it would seem to give a real answer though, instead of getting stuck in a loop because we programmed everything to 'kernel panic' and can't decide when to stop subtracting nothing...dividing into no piles...no division when 0 in the denominator. So if it's a 0 of a distance, would indicate no distance...if it's a zero of a charge, would indicate no charge...if it's a zero of mass, it would indicate no mass... *shrugs*

    --
    There are three kinds of people in the world. Those that can count, and those that can't.
  132. 20 years of programming? by Anonymous Coward · · Score: 0

    20 years of programming, and you can't see the harm in this? I suspect that 20 years of programming is actually 1 year of programming, 20 times.

  133. Special cases by phantomfive · · Score: 2

    Once a biologist, a mathematician, and a programmer were out riding in a Jeep on safari in Africa. Suddenly, there appeared, in a heard of zebras, a white zebra! This following conversation ensued:

    Biologist: "A white zebra! We discovered a new species! We'll be famous!"
    Mathematician: "Technically, we only know that it's white on one side."
    Programmer: "Oh no, a special case!"

    Programming is full of special cases. Part of being professional is learning to deal with it. There is no technology, no setting that will get rid of them for you.

    --
    "First they came for the slanderers and i said nothing."
    1. Re:Special cases by Anonymous Coward · · Score: 0

      In my opinion, all real programming is edge cases. No serious application is without them. It's not possible to build anything useful if you don't handle the edge cases. I think it's Dunning-Kruger. New programmers (and executives) don't understand edge cases, think everything is easy. Cause everything *is* easy if you don't handle the edges.

    2. Re:Special cases by Anonymous Coward · · Score: 0

      Nice. The version of the joke that I heard is:

      An astronomer, a physicist and a mathematician are in a train from England to Scotland and as the train crosses the Scottish border they see a black sheep in a field.

      The astronomer says: Good heavens, all sheep in Scotland are black.

      The physicist replies: That's going a bit far, but Scotland does have one black sheep.

      The mathematician sadly intones: There is at least one sheep in Scotland, at least one side of which is black.

      Which reminds me of a saying: There are only three numbers in physics - 0, 1 and infinity.

      And typing this reply reminds me that a practical definition of infinity is the time it will take Microsoft to produce a workable version of Windows to use on netbooks.

    3. Re:Special cases by Anonymous Coward · · Score: 0

      It turned out it was just a f*cking horse.

  134. 0/0? That's when God speaks to me by jclaer · · Score: 1

    0/0 is when God is telling me my project will not succeed. Don't cut her out of the conversation!

  135. Re:x/0 does not equal 0. by Xtifr · · Score: 3, Insightful

    You only think this makes sense in the real world because you phrased the answer improperly."No one gets the apple" does not answer "how much of the apple does each person get?" The answer to "how much of the apple does each person get?"is "the question makes no sense because there are no people, so there is no 'each person'." Which is the real-world equivalent of what the mathematics says ("No answer/not-a-number").

  136. The obvious answer by Anonymous Coward · · Score: 0

    42

  137. Re:When a man is tired of checking for divide-by-z by anonymous_wombat · · Score: 2

    Or maybe after 20 years, he should stop dividing by zero, either way.

  138. Re:x/0 does not equal 0. by Wraithlyn · · Score: 1

    You have one apple and no people, no one gets the apple.

    Which means no division takes place. You are not dividing by zero, you are avoiding the division entirely, since the denominator is zero.

    Which is exactly how "the math" would handle it.

    --
    "Mind, as manifested by the capacity to make choices, is to some extent present in every electron." -Freeman Dyson
  139. No by Anonymous Coward · · Score: 0

    No you fucking hipster idiot. If you're really coding for 20 years, this can only mean this is some shitty attempt to get coverage for your pathetic existence.

    You can't possibly be so stupid to ask this question after 20 years of coding.

    Fuck you.

  140. Divide by zero != zero by CODiNE · · Score: 1

    Easiest way to see this is by graphing 1/x
    https://en.m.wikipedia.org/wik...

    Notice from the negative side y is approaching - infinity as x nears 0, but from the positive side, when x approaches 0 y is becoming + infinity.

    So it's not the same as multiplying by 0 where everything results in 0. It's really and truly undefined. You can't average +/- infinity and get 0, it's the gap between them. It doesn't exist.

    If you ignore a divide by zero, your results will be unpredictable and often nonsensical. For example:
    The classic algebra trick to "prove" 1 = 2

    --
    Cwm, fjord-bank glyphs vext quiz
  141. Special Operator by Anonymous Coward · · Score: 0

    Add a special operator that implies division by zero is zero. I propose /.

  142. Stupid Question by Eddy_D · · Score: 1
    This is a stupid question.

    Division by zero creates an answer that is beyond the range of whatever finite field number set you are using. It must generate an exception as it cannot be solved with the range of numbers that the machine is using.

    Always remember that all math you do within a software program has to play nicely within the defined boarders of the number sets used by the compiler. The program fails if it traverses outside of this boundary.

    The resulting NaN and exception (eg. fault signal) is correct and should not be changed.

    (Note: I am not including mathematical modelling languages which may have some concept of a non-finite number field.. not aware of any existing anyways...)

    --
    - I stole your sig.
    1. Re:Stupid Question by mr_mischief · · Score: 1

      IEEE floating point has positive and negative infinity, but there's not enough information in "/ 0" to say which is which considering true 0 is nonpositive and nonnegative (despite signed zero for convenience). There's a gap in the graph.

      Try breaking it down into grade-school division for people though. Why? Because you can subtract 2 from 6, three times and build up the result as grade school children are taught, leaving 6= 1 + 4 / 2 = 2 + 2 / 2 = 3, but you can't take subtract 0 from itself 0 times leaving 0 + 0 / 0 to be simplified and expect it to make any progress. There is literally nothing to divide it into. x / 0 where x > 0 comes out to be x / 0 = 0 + x / 0 = 0 + x / 0 ad infinitum, or what a graph of 1 / x shows, approaching infinity. Where x < 0 it approaches negative infinity. Where x = 0 it never reduces. In other cases it reduces to a case that may or may not be useful.

      The simplest way to define x / 0 were we to define it is that it is irreducible. 5 / 0 = 5 / 0 and 22345 / 0 = 22345 / 0 which is about useless without handling it as an exception anyway. This is unless one is doing other math and can therefore cancel out zeros, but then that would have to be done beforehand or in the exception handler/error checking code, which means it still needs to be handled as an exceptional case.

      In certain applications it's okay to approximate to +inf or -inf or MAXINT or MININT or 0 but it's application-specific. There can't be a rule in the hardware or the language. The exception handler can do the approximation (and can log that it's an approximation or alert the user or whatever) or can fail out to user intervention if necessary. The exception is always the right default for an exceptional situation. :-)

  143. Well by Anonymous Coward · · Score: 0

    Any default value assigned is not logical nor correct. Sure you might understand the hack but what about the next developer? Best to determine and fix what happened beforehand, what caused the /0 situation to exist in first place.

    Anything less is simply a hack.

  144. Congratulations! by Anonymous Coward · · Score: 0

    Congratulations, moderators.
    Slashdot has officially jumped my shark.
    This was such pure drivel I can no longer even read you in private, the embarrassment is so great.

    Goodbye.

  145. Consider remainder by Anonymous Coward · · Score: 0

    On some CPUs divide by 0 results in 0, as there is no remainder operation you compute it by multiplication and subtract. ie.

    x % y = x - ((x / y) * y)

    Imagine a hashtable like operation:

    buckets[key.hashCode() % hashtable.length]

    If the table is empty then length may be 0. As divide by 0 is 0 then:

    x % 0 = x - ((x / 0) * 0)
                        = x

    This results in memory accesses corresponding to the key's hashcode. The behavior was undefined but rather than accessing the 0th element, as it would say on x86, it can result in crashes...

  146. [0/1] button by Anonymous Coward · · Score: 0

    There is just such a switch. It has [0/1] printed on it, and is often quite large. If you want 0/0 to be zero, set this switch to the 0 position. If it's a push button, you may have to push and hold it for ~6 seconds.

  147. Why not just declare all variables as strings? by RyoShin · · Score: 1

    A few years back I made a pretty important report that listed percentages. At the time it didn't seem to matter what happened when data was missing, so I created a function that would take a numerator and denominator and spit out 0 if the denominator was 0. (This was in SSRS, so I couldn't use IF since it processes every part of the function regardless of the boolean outcome.) Looking back, while this hasn't caused any problems that I'm aware of, I regret the decision. Displaying -- is actually more informative than 0%, because it tells the user that the data is not available, not that it's 0%, which can be misleading.

    Some day I'll fix it when I have time (and am not browsing Slashdot), but my word of warning to you is: don't. /0 is a special case, and should be treated specially. Don't care about the output? Check for a 0 denominator and just return 0 immediately. But don't try to do this globally, because one day you will need to handle /0 specially, forget to, and that kind of setup will bite you in the ass.

  148. It should return -1 by Anonymous Coward · · Score: 0

    That way we can check for errors just like with any system call or C function that can have 0 as valid return value.

  149. lol give me a break by Anonymous Coward · · Score: 0

    watching all these nerds freak out over nothing is hilarious. You'll probably be fine.

  150. That must be a joke. by drolli · · Score: 1

    I take that the OP is neither a mathematician nor a physicist (as i am). NaN is a reasonable "Default" value for 1/0, and has the advantage that it propagates without you checking for it.

    A physical or engineering simulation which divides by 0 should return NaN or terminate.

    And yes, the serious reason would be that if an engineer uses ANSYS to validate if the bridge is structurally stable, i donâ(TM)t want that some asshat intentionally accepts bad meshes (i.e. meshes with "empty/zero sized cells" without errors.)

    1. Re:That must be a joke. by michael_cain · · Score: 1

      NaN is a reasonable "Default" value for 1/0, and has the advantage that it propagates without you checking for it.

      Or disadvantage that it propagates. Many years ago I spent weeks banging my head against a pile of 10,000 lines of badly structured Fortran on CDC equipment that I had inherited responsibility for. That hardware cheerfully allowed division by zero, storing the equivalent of NaN as the result. At a relatively enormous distance away in both source code and execution, the NaN was used in an addition operation and at that point the machine generated a fault. Ultimately the problem was an off-by-one upper limit in a DO loop, but finding it made me crazy. It would have been far easier to find if the divide-by-zero had generated a fault.

      Ever since, I have been rabidly of the opinion that divide-by-zero is an error condition, and that execution can proceed only if the programmer has provided some sort of try/catch structure that catches the fault.

    2. Re:That must be a joke. by gweihir · · Score: 1

      Even any competent CS type should know that this proposal is not only fundamentally flawed, but dangerously so. If something so incredibly stupid would be done, it would kill people and companies.

      --
      Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
  151. Re:x/0 does not equal 0. by Dunbal · · Score: 2

    Infinity does not exist. Real mathematicians (ie - NOT you) only speak of numbers APPROACHING infinity. So, as the divisor approaches zero, the quotient approaches infinity. You cannot have infinity as a quantity since it does not exist. Otherwise what happens when you divide infinity by zero, and is that new infinity the same as the first infinity?

    --
    Seven puppies were harmed during the making of this post.
  152. Because it should never happen. by sbaker · · Score: 1

    Whenever you divide by zero, the problem ISN'T the division - it's the previous code that either assumes that dividing by this number will produce a valid result, or is doing something wrong in turn.

    Checking - and somehow kludging - a divide by zero does nobody any good. You have to ask WHY you're dividing by zero and what it should mean.

    I *want* divide by zero errors because they inform me that I'm doing something wrong elsewhere.

    (And even if you wanted to kludge it - returning a very large number would be a better choice than zero...but don't do that).

    Bottom line - if you're doing lots of div0 tests then you're doing something wrong in many other places!

        -- Steve

    --
    www.sjbaker.org
  153. Re:x/0 does not equal 0. by Dunbal · · Score: 1

    The Limit as x aproaches 0+ of a/x = infinity. But the Limit as x approaches 0- of a/x = negative infinity.

    Incorrect.

    The Limit as x aproaches 0+ of a/x = approaches infinity. But the Limit as x approaches 0- of a/x = negative infinity.

    --
    Seven puppies were harmed during the making of this post.
  154. Re:x/0 does not equal 0. by Anonymous Coward · · Score: 0

    You have one apple and no people, no one gets the apple.

    Uh, no, you get to keep the apple. It doesn't magically disappear. If there's no people, then there's no apple, because you don't exist either.

  155. We vere talking about integers by Ketorin · · Score: 1

    There has been a lot of talk about how division by zero should be interpreted in mathematics, with real numbers; the concept of limit has been touched.

    What I'd like to hear would be some proper math guy's interpretation of this issue, how pure integer maths (discrete math?) treats this? All I personally can think of would be the a = divider × quotient + remainder thing. We know that anything times zero is zero, which leaves a = remainder; quitient may be any value, so strictly zero is not incorrect in this regard.

  156. We know how the Submitter's error handling works! by Anonymous Coward · · Score: 0

    If the Original Submitter can't even *imagine* when x/0 shouldn't return 0, then the Submitter's error handling must necessarily ALWAYS return 0. Ironically, this means that his/her code wouldn't suffer one bit and might actually improve by some benchmarks (it never handled x/0 properly, so it'd at least reach its incorrect result slightly faster)

    "0" is typically as far as possible from the two possible vaguely sensible numeric results (MAXFLOAT and NEGMAXFLOAT) unless the Submitter SO consistently fails to handle indices (in loops, etc.) correctly that a zero index is overwhelmingly the cause of their DIV BY ZERO.

    Keep fighting the good fight. We can all benefit from alternate views on the basic math -- but this submitter's problem is a terrible coding style

  157. Re:x/0 does not equal 0. by Quirkz · · Score: 1

    Well, in the real world you also can't give two apples to half a person, so this whole analogy is pretty off.

  158. Re:x/0 does not equal 0. by Anonymous Coward · · Score: 0

    Except, if there is no one there to divide the apple by, then there is no division.

    Real world says if there is no-one to get the apples, then no division needs to be done. Not just go ahead and defy logic.

  159. Re:x/0 does not equal 0. by Moof123 · · Score: 1

    Yep. Capture the zero, and with some proper insight you set it to some appropriate non-zero approximation of zero like 1e-6 or 1e-15. The choice usually reflects knowledge of the situation at hand. But often I'd rather a program stop and tell me something bad has happened rather than just patching around it and carrying on.

  160. I'm tired by nyet · · Score: 1

    After 20 years of programming, I'm tired of checking all the return values of all the functions I call. Is there a way we can agree that functions should never return an error? Is there ever a case where you want a function to return an error?

  161. Re:x/0 does not equal 0. by Darinbob · · Score: 1

    Or a +1 Dope Slap button.

  162. "I'm a lazy bastard" by msobkow · · Score: 1

    "I'm a lazy bastard. Can anyone make my job so easy that I can just sleep at my desk for eight hours instead of working? I don't actually care about the quality or correctness of my work, I'm just tired of having to actually work for a living."

    --
    I do not fail; I succeed at finding out what does not work.
    1. Re:"I'm a lazy bastard" by msobkow · · Score: 1
      --
      I do not fail; I succeed at finding out what does not work.
  163. 20 Years? by NicknameUnavailable · · Score: 1

    And you are still allowing laziness to overshadow reason? The idea you have 20 years programming experience is seriously suspect if you think of adding a "system wide" default for divide-by-zero AND think it should be adjustable. It's so absurd you may have stuck my eye wide open in an expression of shock.

  164. Re:x/0 does not equal 0. by tristes_tigres · · Score: 0

    We need a special big stick to slap morons like RackinFrackin for ignorant comments like the one above . What's worse, he is "correcting" someone who knows better than him.

  165. What's the harm? by TheCreeep · · Score: 1

    You end up in undesirable situations like having a share button on slashdot after each story.

  166. Re:x/0 does not equal 0. by tristes_tigres · · Score: 2

    No he isn't. He is right, too.

  167. Duh by O('_')O_Bush · · Score: 1

    The obvious answer is that returning 0 for 0/0 would be a lie.

    --
    while(1) attack(People.Sandy);
  168. Why not 1 / 0 = 1? by mfearby · · Score: 1

    At the risk of incurring the wrath of "the old ones" of programming, why on earth not? Multiplying by 0 results in 0, so dividing by 0 could equal 0 too. Better still, if you're dividing it by 0, then you're not even dividing it at all, so perhaps the result should be the number other than 0? And if you're dividing 0 by 0 then the answer should also be 0.

  169. Re:x/0 does not equal 0. by Darinbob · · Score: 1

    "Well defined" is poorly defined here.

  170. actually a good idea, sort of by v(*_*)vvvv · · Score: 1

    System-wide default error handling would actually be useful. It is completely up to the programmer to make sure nothing unexpected happens, but that is true even without the feature. And it isn't as if there is no default already... it just isn't customizable on a system-wide or better yet, scope basis (in most languages).

    This isn't about invalidating any logical tenants. It is still up to the code to know how to handle errors. For there to be easier methods of instructing default behavior cannot be a bad thing.

  171. Re:x/0 does not equal 0. by Anonymous Coward · · Score: 0

    You do not really understand your real world example. You are switching reasoning, which is exactly what the software is doing:

    4 apples for 4 people -> each person gets 1 apple
    4 apples for 2 people -> each person gest 2 apples
    4 apples for 1 people -> each person gets 2 apples
    4 apples for 0 people -> each person gets ???????
    Because the formulation you did use does not work in this case you switched to:
    4 apples for 0 people -> no one gets an apple
    You use an exeptional form of answer in this case in natural language.
    Software does the same, it reacts in an exeptional way.

  172. IMHO Zero as a divisor should always be an error by Pharago · · Score: 1

    Division by zero has no meaning as a direct computation and will most of the time cause an exception.

    Whatever factor is being divided, it must have a special case when the divisor equals zero.

    Like for example:
    X / (Y == 0.0f ? 1.0f : Y)
    X / (Y == 0.0f ? X : Y)

    It will always depend on the factors being computed, their meaning, and the context in which they are being computed.

    A system wide default value would remove that nice exception and then you will have to check by hand every division looking for some 'unknown bug'.

    In any case, you DO have (at least in windows) a way of setting your own exception handlers and just do nothing when the exception is raised, although you lose your current execution context, but hey, if you have to ask...

  173. Depends on the application I suppose. by hey! · · Score: 4, Insightful

    For certain kinds of abstract algebras division by zero is even defined, although typically as a special element like infinty, but not 0 (the additive identity element) which would lead to all kinds of peculiar situations: like 0 * 1/0 = 0, so 1/0 has to be regarded as both 1 and 0 at the same time.

    BUT if you're dealing with regular numbers or anything that obeys the axioms of an algebraic field, division by zero always represents a failure of the assumptions under which you undertake the calculation. Since it is a failure of assumptions it should always be treated as an exception to normal logic flow. If the correct -- or more accurately speaking the safest -- course of action to take is to assign a value of 0 to a calculation then of course you can do that, but that's still a case of exception handling. Building that as default behavior FORCES a certain response to an exception which of course the language designer can't possibly know is the safest response.

    In fact, even implicitly allowing division by zero in a sequence of algebraic manipulations can lead to faulty results even without actually performing the arithmetic operation in question. That's behind several algebraic "paradoxes" that have made the rounds of the Internet over the years, such as the following algebraic "proof" that "2 = 1":

    Let a = b
    [1] a^2 = a*b // multiply both sides by a
    [2] a^2 - b^2 = ab - b^2 // subtract b^2 from both sides
    [3] (a-b)*(a+b) = b * (a - b) // factor both sides
    [4] a + b = b // divide both sides by (a-b)
    [5] b + b = b // substitute b for a on the left side
    [6] 2b = b // collect terms
    [7] 2 = 1 // factor out b

    It all looks kosher, but it's not because there's a division by zero in the *algebra*. I've actually seen programs that give faulty errors because the programmer simplified expressions in ways that commit this exactly blunder. The language and compiler can't catch this because the division by zero occurred in the programmer's head.

    --
    Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
    1. Re:Depends on the application I suppose. by Anonymous Coward · · Score: 0

      You just gave my brain a cramp. Very good.

    2. Re:Depends on the application I suppose. by Anonymous Coward · · Score: 0

      This "demonstration" is well known.
      I am always puzzled about the conclusion.
      At [4] or at[6], remove b on both side and conclude a = b =0.
      So the conclusion should be: for all a and b such that a = b, a and b are equals to 0.

    3. Re:Depends on the application I suppose. by serviscope_minor · · Score: 1

      That's still faulty. The original expression is "a=b" and that's it. There's no valid way to conclude that they must be equal to 0, since any number satisfies the original expression.

      Your route is a subtler manifestation of the same problem. it's dividing a*(b-a) by (b-a) which leads to nonsensical answers, including yours.

      --
      SJW n. One who posts facts.
  174. Mars Rover? by chavez+chiu · · Score: 1

    I can think of at least one scenario where it makes sense. Say you're building the next Curiosity, you've done all the right things, dealt with exceptions, quality assurance, code reviews etc.. Wouldn't it be better if an exceptional divided by zero exception wouldn't brick your rover by default? All the bashing, I think it comes down to priority.

  175. seems simple enough? by Anonymous Coward · · Score: 0

    dividend = 0
    divisor = 0

    if (divisor == 0) { alert('cant do that!') } else { // go on }

    log a warning? error?

    trace the data back when it happens and find out wtf wtf means?

    1. Re:seems simple enough? by OrangeTide · · Score: 1

      I always write the result of 0/0 to a random location in memory.

      --
      “Common sense is not so common.” — Voltaire
  176. It's undefined in C/C++ by ZigMonty · · Score: 1

    In C and C++ it's not defined to throw an error. It's undefined behaviour and the compiler is free to do whatever it wants.

    Typically that means doing nothing special, and on x86, the instruction itself traps when zero is the denominator. On powerpc, there's no trap and you get zero. Each processor has a different, defined behaviour.

    However, if the compiler can prove that, along any particular path, the denominator is guaranteed to be zero, it's allowed to delete that entire path, as the program is undefined if that path is followed, so it can assume it isn't followed. It's not guaranteed that your program will execute normally up to the divide by zero. A soon as the divide by zero becomes inevitable, the program is undefined and the compiler is free to do absolutely anything.

    If any of the above scares you, C and C++ aren't the languages for you. It always amazes me how many people write non performance critical code in C. But when you need speed/efficiency, there's no replacement for C or C++ and a good optimising compiler.

    Also, to the original poster, no, defining it to be zero doesn't make sense. PowerPC did indeed do that. But the number desired isn't always zero. It's undefined in mathematics for a reason: in different situations, it logically should be a different value, and there's no way to resolve the contradiction. Hence if you do divide by zero, your program is seriously flawed.

  177. How to disable div/0 errors! by Hobadee · · Score: 1

    Here is a code snippet which, when translated from this sudo-code into a real language, will always return 0 instead of div/0 errors!

    try{
            foo = bar / baz
    }
    catch{
            foo = 0
    }

    --
    ...Had this been an actual emergency, we would have fled in terror, and you would not have been informed.
    1. Re:How to disable div/0 errors! by Anonymous Coward · · Score: 0

      396 Comments/0 = too much time for this silliness

  178. Doing it wrong by Anonymous Coward · · Score: 0

    Stop using raw data types?
    Rather than putting 'magic' or just wrong values in the result, values should have quality flags associated with them, such as
          uninitialized
          overrange
          underrange
          infinity (+ and or -)
          undefined
          propagated bad quality from previous operations with other (bad) values
        -others

    If a quality flag is set, something is wrong.

  179. Two words by Anonymous Coward · · Score: 0

    CODE COWBOY!

    Yeeeeeeeha!

    Code Cowboy thinks to himself "I could either get the shit out of my code so it's works right or I could just wrap the code in tinfoil, spray on some gold color, put some air freshener on to cover the stink and call it a gold brick instead of a shit brick!"

    That's the way you do it, money for shit, get your cocaine for free! I want my, I want my, I want my code cowboy attitude!

  180. Re:x/0 does not equal 0. by Anonymous Coward · · Score: 0

    Ever heard of functions? In _your code_ if you need a certain behaviour to repeat over and over, ie. because you need a certain number to become 0 when not distributing something out to anyone, you make a function for it. Your function, your rules.

    Math is just a tool. In the right hands it can do wonders. In the wrong, you can prove anything by misuse, confusion and diversion.

  181. Division by zero does NOT equal zero! by WolphFang · · Score: 1

    Anything divided by zero is by definition infinity. Not zero. I definitely do NOT want your default anywhere near me. If you can't represent the division by zero as infinity or handle otherwise as a special case that does NOT result in any numeric value the program should CRASH or THROW AN EXCEPTION. Period.

    --
    leather-dog muksihs
    Blog: @muksihs
  182. See Goldberg's article by Hotawa+Hawk-eye · · Score: 2

    There's a classic document appropriately titled What Every Computer Scientist Should Know About Floating-Point Arithmetic. The "Special Quantities" section discusses plus and minus 0, denormal numbers, infinity, and NaN and offers some rationales for why those special values exist in IEEE floating-point arithmetic.

    1. Re:See Goldberg's article by Anonymous Coward · · Score: 0

      Who said this was about floating point?

  183. Hypothesis-Conclusion by flug · · Score: 1

    One of my math professors worked for some kind of engineering firm in his earlier days. This was probably back in the 70s or so.

    They were creating some kind of device and it was based on a math theorem of some kind--the usual thing where there are hypotheses A, B, C and **if those are exactly fulfilled** then there is a little algorithm you can use to give result X, Y, Z.

    So his fellow engineers used this theorem, using the algorithm and result X, Y, Z but blithely ignoring the need to check that hypotheses A, B, C were fulfilled.

    Prof warns fellow workers that this isn't going to work and is a recipe for disaster.

    Fellow engineer-workers can't understand what the problem could possibly be, so proceed to manufacture the device as-is. It is some kind of hard-wired measuring tool or such, with custom manufactured circuit boards that bake in the programming logic etc etc etc.

    Result: Device worked perfectly most of the time but occasionally, randomly, mysteriously completely malfunctioned. Of course--it worked perfectly whenever the hypotheses were fulfilled and complete malfunctioned otherwise.

    Other result: Firing of numerous people on engineering team and complete re-design of the device from the ground up.

    To answer your question: The reason not to follow your plan is that ALL of your programs are going to behave like this device. They will work fine most of the time (if you are lucky) but then there will be random and very-difficult-to-detect bugs that appear only during certain relatively rare and difficult-to-duplicate circumstances.

    In short--nightmare material.

  184. There's so Much Wrong Here I Can't Even... by ImprovOmega · · Score: 1

    Why stop there? If I get a file exception it should just write to syslog by default! If I have a null pointer it should just write to the last array I referenced! Array out of bounds exceptions should cycle back around to the start of the array so I never see that error either! I'm sure nothing bad would ever happen ever from implementing all of these!

    Seriously son, it's called an error for a reason. Correct your invariants so it can't happen or monitor for the exceptions and handle them gracefully. It's bad enough that incrementing an integer past its max wraps it back around to its min. Let's not make coding even more treacherous, m'kay?

  185. The *only* possible valid default would be NaN by mark-t · · Score: 1

    Division doesn't really exist in the sense of a mathematical operatoin. Division is best thought of as a convenient shorthand for multiplication by the multiplicative inverse of a number. The multiplicative inverse of a number is well defined to be such that a number multiplied by its multiplicative inverse equals the multiplicative identity value, which is 1. There is no number that can be multiplied by zero to get a value of 1, however, so "dividing by zero" is like trying to multiply by a number that doesn't exist in the first place.

  186. FAIL by mbone · · Score: 1

    Does anyone want their div by zero errors to result in anything other than zero?

    It is far better to throw an error than to do something massively stupid.

    If your code has anything to do with moving actual physical objects, be it photons or electrons or larger things such as aircraft or spacecraft, your divide by zero errors should be caught and replaced with either an error or if possible with a sensible result. In my experience, with physical things these sensible results are generally not zero, but most commonly plus or minus "infinity" (i.e., something as large as possible). It's also common for a divide by zero to be a symptom of some assumption or approximation failing for the case in question, and completely different code branch may be needed to do the right thing.

    1. Re:FAIL by mbone · · Score: 1

      Oh, and NAN is in the vast majority of cases not a sensible result. It can be fine to report that some variable is NAN (that being an error state or a symptom of the error state), but doing anything with it is crazy IMHO.

  187. Re:x/0 does not equal 0. by Anonymous Coward · · Score: 0

    You're so close, but you missed it.

    In the real world when there are no people, this special case is noticed and the division never occurs. That is what the code should do. Check for cases that would cause a divide by 0 error before the error occurs, not come up with some terrible way to swallow up exceptions that are trying to tell you something bad happened.

  188. This has already been thought of: Transreal maths by Anonymous Coward · · Score: 0

    https://en.wikipedia.org/wiki/James_Anderson_(computer_scientist)#Transreal_arithmetic_and_other_arithmetics

    This seems to make a lot of people very angry, but in the same way as we define i for SQRT(-1) and just carry on, this has 0/0 defined as "nullity" and then you can actually do some rather interesting maths.

    Yes it's nonsense in the realworld, but hey, when did that stop mathematicians? The perspex machine paper has some more information: http://www.bookofparagon.com/Mathematics/PerspexMachineIX.pdf

  189. Why not? by K.+S.+Van+Horn · · Score: 1

    Sure, just choose a default for division by zero. I always prefer silent errors where my software just gets the wrong answer over being informed in no uncertain terms when something is wrong. I mean, the important thing is to keep up appearances, maintain the illusion that everything is okay, isn't it?

  190. Comment removed by account_deleted · · Score: 2

    Comment removed based on user account deletion

  191. Re: x/0 does not equal 0. by Anonymous Coward · · Score: 0

    *puts 2 apples in the lap of a quadruple amputee*
    What can't i do now?

  192. For practical purposes and simplified usage by MondoGordo · · Score: 1
    For most practical purposes you can think of division (1/x) as "chopping up" the numerator into x number of pieces. in the integer domain, as the size of x shrinks towards zero the "number of pieces" of the resulting "size" required to represent the original whole diminishes.

    1/4 = 4 pieces, 1/3 = 3 pieces 1/2 = 2 pieces 1/1 = 1 ... logically then in the integer domain 1/0 = 0 pieces.

    In the real number (float) domain it's obviously more complicated ... 1/0.5 = 2 pieces, 1/0.333333333 = 3 pieces 1/0.2 = 5 pieces 1/0.1 = 10 ... 8o( But that is for the specific infinite domain where x approaches zero ....

    If you take the stance that any float y where y = 0 is for all practical purposes an integer and apply the rule consistently, I can't see having an issue with any typical application programming scenario. Where "typical" does not include mathematical operations beyond everyday computation for the average business user.

  193. Unintended state by Anonymous Coward · · Score: 0

    Typically when writing code, if you're dividing by zero, something f***ed up somewhere. You clearly want to know when this happens; making an erroneous state auto-correct to 0 is a recipe for disaster. I deal with enough suppressed errors at work because of people's crappy coding; I don't need more.

  194. ArcSec(x/0)==Pi/2 by dsmatthews9379 · · Score: 1

    Or so Mathworld tells me, http://reference.wolfram.com/l... because x/0 is a Complex Infinity, therefore the answer must symbolic, NaN and so the answer to your question is that, the harm is that your code could be non-deterministic if you do not define what the outcome should be in each case. i.e. Assumptions are dangerous.

  195. Divide by infinitesimal by Anonymous Coward · · Score: 0

    I would typically want div by zero to be equivalent to dividing by the smallest representable possible float. The result of the division would generally be the largest representable float. That's a long way by zero

  196. Megaharm by Forever+Wondering · · Score: 1

    System wide setting? Most other programs don't want it. What you want is a function you can call at the start of your program: no_div_by_zero_exceptions_in_this_program().

    But, that is a bad idea (tm) because the programming language/system doesn't know the context. That is, what you intend if div-by-zero occurs on a line-by-line basis. That's why you have to have explicit checks:

    if (y != 0)
        z = x / y;
    else
        z = ...; // what you want: x, 0, inf, -1, throw exception, abort program, whatever

    But, this is just a single check out of the things a program has to check for:
    - null pointers
    - array bounds
    - insane/wrong values (e.g. a person's age shouldn't be a negative number)
    - object in wrong state for operation to be performed (e.g. trying to do a database operation when the DB handle isn't locked)
    - ...

    Also, drawing on the recent Linux raid0 problem [where FS corruption was happening], they had something akin to:
        sector_offset = absolute_byte_position / sector_size;
    If sector_size happened to be zero (a programming mistake), silently returning zero here would corrupt the disk/file.

    You've been programming for 20 years? Well, junior [I've been programming for 43--sigh], you've still got a lot to learn. And the fact that you didn't see the harm before you posted proves that.

    --
    Like a good neighbor, fsck is there ...
  197. Nullity! by Anonymous Coward · · Score: 0
  198. While we're at it, pi by jrumney · · Score: 2

    Indeed. And my programs would run a lot quicker if pi was 4. Does anyone really want pi to be anything other than 4?

    1. Re:While we're at it, pi by thegarbz · · Score: 1

      Yes I prefer it to be 3. It's more accurate.

    2. Re:While we're at it, pi by Shaitan · · Score: 0

      Programs definitely run faster with divide by zero errors. They stop pretty much immediately!

      The ideal would probably be to have it be a flag a developer can toggle. Either divide by zero is an error (used for debugging) or divide by zero is effectively no operation, returning the original value.

      6/0 means no division occurred so the answer is 6.

    3. Re:While we're at it, pi by gzuckier · · Score: 1

      Indeed. And my programs would run a lot quicker if pi was 4. Does anyone really want pi to be anything other than 4?

      Anybody remember Fortran 66? You could define numbers to be whatever you wanted. You could put
      1=2
      x=4/1
      print x
      and it would happily print out 2. Now that's the kind of powerful but cooperative computer language we need.

      --
      Star Trek transporters are just 3d printers.
  199. This is a joke, right? by Anonymous Coward · · Score: 0

    For the love of all that's good and pure, please tell me this is a joke.

  200. Re:x/0 does not equal 0. by Verdatum · · Score: 1

    um....source? I got bored confirming, but if I'm reading you correctly, at least Wikipedia disagrees with you https://en.wikipedia.org/wiki/...

  201. Re:x/0 does not equal 0. by mark-t · · Score: 1

    No... the post that RackinFrackin replied to was factually wrong. A number divided by 0 is *NOT* defined as either plus or minus infinity. The definition of division is such that any division by a number is equivalent to multiplying by that number's multiplicative inverse, but 0 does not have such an inverse, so dividing by 0 is like trying to multiply by a number that doesn't even exist.

    In other words, it's undefined. Nothing more, and nothing less.

  202. Re:x/0 does not equal 0. by Dunbal · · Score: 1

    Better than Wikipedia maybe take a math course? I mean, if you want to sound like you know anything when discussing math.

    --
    Seven puppies were harmed during the making of this post.
  203. WTF? by dskoll · · Score: 1

    "After 20 years of programming..."

    Seriously? What language did you program in? HTML4? That's a programming language, right? Just like Pearl and F.O.R.T.R.A.N?

    I think I may have come across your resume...

    1. Re:WTF? by Anonymous Coward · · Score: 0

      I think your evaluation is overly optimistic.

  204. Re:x/0 does not equal 0. by Anonymous Coward · · Score: 0

    How about "not yet defined". You know, just in case.

  205. Re:x/0 does not equal 0. by Verdatum · · Score: 1

    Hmm, I've got Khan Academy agreeing with me too: https://www.khanacademy.org/ma... on his board at 3:16. But, what does he know, he's only one of the most highly regarded sources for learning mathematics online...I'm sure it was just a slip-up that no one seems to have successfully countered in his comments...

  206. And 2 + 2 = 5 by Anonymous Coward · · Score: 0

    What a stupid conjecture.

  207. there's already a good link by surd1618 · · Score: 1

    I hate to say it, because I love Being Right On the Internet, but there's already a great explanation of all this malarkey* on the glorious Youtube
    https://www.youtube.com/watch?...
    and the problem of 0/0 = anything doesn't go away just because a progam finds it in an array operation. It's meaningful.

    * here' I'm using malarkey in the proper mathematicly rigorous way

  208. Your space ship crashes into the sun by Anonymous Coward · · Score: 0

    Your bridge falls over.

    In "gamer world" a pixel gets maxed out to white.

    There is mission critical and then there is graphics.

    There is math. Then there is numerical computation. These are 2 totally different things. Learn the difference.

    Divide by zero raises a processor exception and dumps core. It has always been such. Learn why.

    If you are using C or Fortran on Unix, you have complete control over all of this.

    Start Here:

    http://www.gnu.org/software/libc/manual/html_node/Floating-Point-Errors.html

    Now get the fuck off my lawn.

  209. Re:x/0 does not equal 0. by Anonymous Coward · · Score: 0

    "Infinity does not exist. Real mathematicians (ie - NOT you) only speak of numbers APPROACHING infinity."

    I don't think I count as a real mathematician (but a long time ago in a galaxy far, far away I did get a mathematics degree), so with that caveat:

    As someone pointed out above, there is the one-point compactification of the complex plane; also points at infinity in projective geometry, the use of infinite numbers (and infinitesimals) in Non-standard Analysis, and the Surreal numbers, about which Donald Knuth has written a book "Surreal Numbers: How Two Ex-Students Turned on to Pure Mathematics and Found Total Happiness".

    In short, that's only the tip of an iceberg of actual infinities. Try searching for: Georg Cantor.

  210. I vote for 42.... by David_Hart · · Score: 1

    After all, 42 is the answer to life, the universe, and everything. I'm pretty sure that divide by zero falls under the "everything" category.... (grin)

  211. The set of all numbers by OrangeTide · · Score: 1

    Why can't your floating point unit just return the set of all numbers when you divide by zero? That seems like the right thing to do to me, better than evaluating to 0.

    Don't ask me how to encode the set of all numbers, or what a program might do with that once it got that result, probably throw an exception. *wink*

    --
    “Common sense is not so common.” — Voltaire
  212. FTFY by Anonymous Coward · · Score: 0

    if denominator=0 then return 0;
    else return numerator / denominator;

    QED.

  213. Re: by Anonymous Coward · · Score: 0

    The concept of nothing only exists in mathematically-based logical structures and death; understanding of "nothing" is prevented by human incomprehension.

    You nerds will never find your answer. Peace. *drops mic*

  214. Random by penguinoid · · Score: 1

    Since 0/0 is undefined, it could just replace it with a random number or a default. In a few limited contexts this might be better than crashing. Of course, that option shouldn't be enabled during development and testing. If this were available, the result would be well-defined: the managers will insist to enable the hide-divide-by-zero, and patch it in the sequel.

    --
    Don't waste your vote! Vote for whoever you want, unless you live in a swing state it won't matter anyways
  215. Is it April Fool's by Anonymous Coward · · Score: 0

    Do everyone a favour and get out of programming. The fact that you ask this boggles the mind. The fact that slashdot would POST this, I just cannot comprehend.
    A real, REAL, big W.T.F ????

  216. It depends by Anonymous Coward · · Score: 0

    It depends on exactly what is going on. If its 0/0, then you can assume 0/0 is 0. If its X/0 where X is not zero, then the result is not zero, in fact it tends to want to run off towards infinity. Giving it a value of zero will likely yield very wrong results. If you are calculating Navier-Stokes equations, inflection points might run to zero (causing the entire equation to "blow up" as the result at each inflection point is infinity or at least a very large value). So it all depends on exactly what you are doing.

  217. All wrong. by Joebert · · Score: 1

    10/0=10 10/1=5 10/3=1.25

    --
    Wanna fight ? Bend over, stick your head up your ass, and fight for air.
  218. While we're at it... by Anonymous Coward · · Score: 0

    Let's round pi down to an even three. Who needs all those silly decimal digits, anyway?

    Both of these proposals are absurd beyond belief.

    1. Re:While we're at it... by grahamwest · · Score: 1

      On a Vax you could dereference a NULL pointer and get zero.

      http://www.catb.org/jargon/htm...

      --
      Graham
  219. If it must not happen, assert that it doesn't! by rock_climbing_guy · · Score: 1
    You wouldn't put unsanitized inputs into a database, would you?

    You wouldn't post someone's comment on your web page without escaping it first, would you?

    So then when should your code that does division not check that its inputs are valid?

    --
    Wh47 d1d j00 541, 31337 15n't t3h r0xor5 ne m0r3???
    1. Re:If it must not happen, assert that it doesn't! by Dynedain · · Score: 1

      Because in some languages and programming formats (especially ones where this kind of problem would come up frequently) it's painful to do validation checks before every mathematical operation. Jamming crap into Excel formulas comes to mind (thank God I don't have to do any real work there).

      I could totally understand the desire of a language that featured this or had it as a flavor setting. I think it could allow for some interesting logical expressions and verbosity reduction if it was understood to operate in a consistent manner.

      --
      I'm out of my mind right now, but feel free to leave a message.....
  220. While we're at it... by mysidia · · Score: 1

    Why don't we get rid of segmentation faults too when dereferencing the null pointer? What's the harm of just ignoring any program write to unmapped memory, and returning all zeros on a read attempt?

    How about an option to make an abort() statement from a library function return 0; instead?

  221. Surprised no one has thought of this by Anonymous Coward · · Score: 0

    Just do all your calculations in Roman numerals. They didn't have zero in their number system, so you're pretty much good to go.

    Jeez, 500+ unhelpful posts... can I get the little green Yahoo Answers checkmark?

  222. Re:x/0 does not equal 0. by gerardrj · · Score: 1

    If you have 1 apple and no people then no division takes place. The answer is not 0 slices it's "no process completed". The answer is not "no one gets the apple" because there aren't any "ones" in the system to not get the apple, there is no solution other than to scream.
    The problem is you don't understand how to properly express the real world in mathematical or algorithmic terms.

    --
    Article X: The powers not delegated... by the Constitution...are reserved...to the people
  223. IEEE floating point: divide by zero is infinite by Anonymous Coward · · Score: 0

    In certain situations, like geometry, it may be appropriate to divide by a number that approaches zero. Due to the limited precision of floating point number, -0.0 and +0.0 can be seen as almost zero. Therefor IEEE defines the result of division by 0.0 to be Infinite (signed appropriately).

    I think this mode for floating point calculations is configured by default (I believe that it is a default is specified in the IEEE spec as well) on most CPU bases systems. Other modes include raising an exception/interrupt.

    Since integer math does not include infinite it is not possible to define what to do at divide by zero, except for causing an exception/interrupt.

    From an engineering point of view having divisions by zero result in infinite is completely valid. But that is because engineers live in a real world of inaccuracies and limits, while mathematicians live in a world of theory where everything is exact.

    Now comes the 'however'. Exceptional floating point values, like NaN are handled very slowly on a x86 by both MMX/SSE and the floating point 'co-processor'. I am talking about hundreds of times slower in case of the co-processor, MMX is faster but still slower than normal processing. I am not sure if infinite or denormal numbers (very small values near zero) are part of the special slow-path values.

  224. On the Theoretical Plausibility of Dividng By Zero by jdeisenberg · · Score: 1

    I remember reading this article years ago in Datamation. http://www.retroarchive.org/cp... Long-winded and filled with marvelously specious arguments.

  225. Re:x/0 does not equal 0. by dcollins · · Score: 1

    False.

    "The expression 1/0 is not defined either as +INF or INF, because although it is true that whenever f(x) -> 0 for a continuous function f(x) it must be the case that 1/f(x) is eventually contained in every neighborhood of the set {INF, +INF}, it is not true that 1/f(x) must tend to one of these points. An example is f(x) = (sin x)/x (as x goes to infinity). (The modulus |1/f(x)|, nevertheless, does approach +INF.)"

    https://en.wikipedia.org/wiki/Extended_real_number_line

    --
    We know where leadership by an anti-intellectual "strongman" who scapegoats minorities and likes boisterous rallies goes
  226. Re:x/0 does not equal 0. by dcollins · · Score: 1

    There is a system called the extended real number line which does in fact have +INF and -INF as usable values. As you expect, division by zero is still undefined even in that situation.

    https://en.wikipedia.org/wiki/Extended_real_number_line

    On the other hand, there is an extended complex plane (Reimann sphere) with a single added "point at infinity" for which one can consistently define 1/0 = INF. But this is not the same as any standard computer number format, of course.

    https://en.wikipedia.org/wiki/Riemann_sphere

    --
    We know where leadership by an anti-intellectual "strongman" who scapegoats minorities and likes boisterous rallies goes
  227. Re:x/0 does not equal 0. by dcollins · · Score: 1

    And is the apple still consumed as in the first scenario, or does it need to be treated differently afterward?

    --
    We know where leadership by an anti-intellectual "strongman" who scapegoats minorities and likes boisterous rallies goes
  228. Simple Answer by dcollins · · Score: 1

    The definition of division is that it's the inverse of multiplication: a/b = x means x*b = a. For example: 6/3 = 2 because 2*3 = 6.

    But saying that 6/0 = 0 means 0*0 = 6. Which is obviously incorrect for any purpose.

    --
    We know where leadership by an anti-intellectual "strongman" who scapegoats minorities and likes boisterous rallies goes
  229. Re:x/0 does not equal 0. by Anonymous Coward · · Score: 0

    As others point out math uses infinity as something that is approached, further computations with it are only meaningful with enough context to get the rate of approach. The rate of approach can then be compared between multiple computed infinity values when they appear in the same equation and may give you a result that is actually usable or just another number approaching infinity. ( This is from memory, didn't have to use math like that in a long time so beware of errors)

    Math as done in most programming languages is incapable of giving you a usable value. In math infinity/infinity for example can give you a result as described above, a programming language like python gives me a NaN, as in not a valid number. The infinity values are more an error flag, you cannot use them, since they do not hold context other than that you exceeded the range of representable values in one direction.

  230. Re:x/0 does not equal 0. by brantondaveperson · · Score: 1

    The thing is this, the answer to the question 1/0 = x, for instance, must satisfy the equation x * 0 = 1. But we know that for all numbers, a multiplication by zero will always equal zero. Therefore, the equation has no solution.

    Additionally, infinity is not actually a number at all, so it can't be the solution to a polynomial of any sort, because the basic requirement of any solution is that it be a number.

    Apologies for the slight sarcasm there - but this stuff does come up a lot. 1/0 is not infinity, positive or negative. Sorry.

  231. You, Sir, are absolutely right by Anonymous Coward · · Score: 0

    If you get such an error it indicates a very fundamental problem wit the logic of the program.

    Indeed, there is a very fundamental problem with wit.

  232. Not really a problem here by Anonymous Coward · · Score: 0

    This is not an Algebra problem. It's a computer science question really.

    When you go over the max in a register and add a number, it folds over. (65536 + 1 = -65535)

    This only happens in computers and not in real math. So we need a flag for it and we know we call it the carry flag.

    So x/0 is infinite, at least when you approach /0. You cannot make it the max of a datatype or register, so you need another flag. I think its just what this flag is called that is bothering you, or how most code chooses to handle it, not the fact that there is a flag for it at all.

    I'd just replace the "DIV ERROR" assert with just a flag that shows the infinity sign (and never ever use it in real production anywhere).

    Does that work?

  233. Re:x/0 does not equal 0. by Your.Master · · Score: 1

    Before asking wikipedia to take a math course, I suggest you read this wikipedia article, which aligns with the math courses I took: https://en.wikipedia.org/wiki/....

  234. 0/0, x/0 and (-x)/0 should be defined separately by Anonymous Coward · · Score: 0

    0/0, x/0 and -x/0 should be classified as three separate items:

    0/0 should result in a value of 0
    x/0 (where x is positive and greater than 0) should result in the highest positive value the computer running the calculation can generate.
    -x/0 (where x is negative and less than 0) should result in the lowest negative value the computer running the calculation can generate.

    -joe the machine

  235. IOCCC style by leob · · Score: 1

    For integer division, just say

    inline int div(int a, int b) {
            return (a&-!b)/(b|!b);
    }

    Then use div(x, y) to your heart's content.

    1. Re:IOCCC style by leob · · Score: 1

      Oops, should have been
      inline int div(int a, int b) {
                      return (a&-!!b)/(b|!b);
      }

  236. Dividing by zero indicates an error in your code by Anonymous Coward · · Score: 0

    I have only had code die with a "divide by zero" exception on a few occasions. In each case, close examination found a logic error in my code that was important to address.

    In general, a division by zero error indicates that you are either attacking the problem in the wrong way or are failing to check some boundary condition. Papering over the problem by just setting the answer to zero will leave these logic errors unfixed and cause far worse problems down the line.

    In most cases, checking the denominator to make sure that it is not zero is not actually the best approach. Better is to make sure that your code is written so that there will never be a zero there in the first place.

  237. What software have you worked on? by Anonymous Coward · · Score: 0

    I want to be sure to avoid it at all costs.

  238. You are tired of programming by Anonymous Coward · · Score: 0

    Do something else before somebody gets hurt by your ignorance

  239. Unfortunately not that rare by aepervius · · Score: 1

    I have half a dozen identical anecdote from the time i coached a few people in programming language. It is almost as if there was a block hindering the person to realize that there was no way you could divide by zero. It was not that the fact that there was an error was misunderstood, it was the division by zero which seemed not to be understood. I never had so many problem coaching people with other errors.

    --
    C. Sagan : A demon haunted world:
    http://www.amazon.com/gp/product/0345409469/
    visit randi.org
  240. It's not infinity, it's ill-formed by Anonymous Coward · · Score: 0

    Nope, you can't do that, because there's a continuity fault.

    Infinitessimally less than zero (0-) or infinitessimally more than zero (0+) are both scalar values in the same region of continuity around zero, and they have no scalar separation from it (ie. they're both at zero). In contrast, N/(0-) and N/(0+) are not in the same region of continuity at all, but are two points infinitely far apart along this scalar dimension.

    In other words, N/0 does not have a properly defined value with scalar continuity. It's more akin to the expression having TWO values simultaneously, which of course is nonsense in a scalar context. That's why you should never even attempt to evaluate N/0, even if your arithmetic representation had a symbol for infinity. The result is not infinity, it's simply ill-formed.

  241. CPUs do have a setting for that. by Ihlosi · · Score: 1
    ARMs let you chose if you want a division by zero to result in an exception or in a result of zero (DIV_0_TRAP bit).

    Of course, you need to get down to assembly to mess with this setting, since most programming languages specify a behavior in this case, or behave in an unspecificed way.

    Then again, dividing by zero usually means that there's something wrong with your design.

  242. Let me apply for a mortgage with you company. by Chrisq · · Score: 1

    Let me apply for a mortgage with you company. I'll take a zero term year please. Now what will my repayment be?

  243. armv8 by Anonymous Coward · · Score: 0

    you may want to program on Arm v8, its assembly instructions do not cause divide by zero hardware exceptions, and division by zero simply writes zero into the destination register.

  244. Infinity by Anonymous Coward · · Score: 0

    Why on earth would x/0 be 0?

    With GCC, x / 0 == inf, except for 0 / 0 == NaN.

    I was quite surprised to discover this when as a teenager I was writing a 2.5D (doom style) game. I was looking for a crash bug, and it occurred to be that I had an y/x, with x,y being the view vector. When looking along the Y axis, that would be 0,1, giving 1/0. Turned out that 1/0 gave inf, and the next step then became arctan(inf), which is 90 degrees.

    So, by having X / 0 == inf, (and -X / 0 == -inf), the correct result comes out in the end.

    x / 0 == 0 would give wrong results in basically all cases.

  245. high quality replies by MoreThanThen · · Score: 1

    I would just like to congratulate everyone on the quality of the replies.
    With currently 644 comments and much utilisation of the words 'then' and 'than', everyone has managed to use them correctly.
    644/0 = a beautiful day (Friday too).

  246. Data validation is part of life by bradley13 · · Score: 1

    Validating external data is Programming 101. If you receive a value that cannot be zero, and you cannot absolutely trust the source, then you must check. Data validation is tiresome, but it's part of life.

    Defining the result to be zero is incorrect, and will introduce an unknowable number of follow-on problems.

    For those who may not be aware, when working with floating point values (as opposed to integers), division by zero is just fine. The IEEE standard defines the answer as infinity, which is a valid value. In some applications, this is a perfectly fine result.

    --
    Enjoy life! This is not a dress rehearsal.
  247. Multiplying back by Anonymous Coward · · Score: 0

    How about a simpler approach?

    Division is defined as identifying which quotient, multiplied by the divisor, gives the dividend. So, if D / d = q, then q is defined as the number that can be multiplied by d to get D. e.g., 8 / 2 = 3, and the reason why 3 is the correct answer is because 3 times 2 = 8.

    Now, using that definition, if we had 8 / 0 = x, please tell me what value of x can be multiplied by zero to get eight.

    Oh, there is no such value? Okay, apparently such a value for x is not possible. Similarly, 9 / 0 = x has the same problem, and so does 7 / 0 = x. The pattern here is that we cannot come up with a valid answer to division problems when the divisor is zero.

    Now, on the other hand, if we have 0 / 2 = x, we can say that answer (x) is zero, because then x times 2 gives us the desired original number. So the only place that zero is not allowed is in the divisor (the middle number, with the way I've been writing things out).

  248. Not really the smartest suggestion ever by Anonymous Coward · · Score: 0

    I am surprised that you are still employed if you are having trouble with trivial mistakes after 20 years of programming. Surely you don't program professionally?
    While you are at it, why not just make the computer ignore all of your programming and arithmetic errors, and continue executing your buggy code, and lets also get rid of floating point calculations and do everything with integers. All these fractions are close enough to whole numbers for it not to matter. Yes, you are a really smart cookie with this proposal.
    I'm sure with your level of genius, you will now go and implement a floating point exception handler for your programs that implements your revolutionary laws of arithmetic. Good luck.

  249. It would be even simpler if x/y = 0 for all x, y by Anonymous Coward · · Score: 0

    How is this a real post?

    As long as you're proposing such mathematically bogus simplifications, why not define x/y = 0 for ALL values of x and y? That would make just as much sense, and really let you simplify your code even more!

  250. meadows by Anonymous Coward · · Score: 0

    There appears to be some serious peer-reviewed work on this:
    http://www.sciencedirect.com/science/article/pii/S0304397508008967

    From their conclusion:
    "The theory of meadows depends upon the formal idea of a total inverse operator. We do not claim that division by zero
    is possible in numerical calculations involving the rationals or reals. But we do claim that zero totalized division is logically,
    algebraically and computationally useful: for some applications, allowing zero totalized division in formal calculations,
    based on equations and rewriting, is appropriate because it is conceptually and technically simpler than the conventional
    concept of partial division."

  251. Navigation by Anonymous Coward · · Score: 0

    potential div by zero is reasonable in nav calculations, which is one reason why the complexities of dealing with it are hidden inside the atan2(y,x) function. Both x and y can legitimately go to zero but the function returns +/-pi/2 when y!=0 and x==0. Other cases are matrix operations where it makes sense to check for absurdly small values & replace them by e.g 1e-12 (or whatever is appropriate to the problem) to make the calculations stable.

  252. Only if you want your aircraft to crash by dogsbreath · · Score: 1

    Your assumption is simply wrong. It can only be expressed as "not a number" and your code should catch this.

    There are all sorts of examples to show how allowing div by zero leads to any desired numerical result and not necessarily zero or infinity. My fave is sin(1/x)/x.

    First note that f(x) = sin(1/x) is bounded by +1 and -1 but as x -> zero there is not even a limit. The sin frequency increases but it never tends towards any single value. Simple and wonderful.

    Now try [sin(1/x)]/x, which has no upper or lower bounds and no limit as x -> zero. Beautiful.

    Given your desire to simplify things, this function shows that setting div by zero to ANY number is as good as zero or max or any value you like. The logical conclusion is that any result with a div by zero in it is meaningless.

    Coding calculations is very much about handling exceptions, such as div by zero, and controlling floating point accuracy. If you don't like dealing with what is required and if you don't understand why then perhaps you should leave the math to others. Seriously.

    BTW, google will graph these functions for you... just enter "plot sin(1/x)/x" into the search dialogue.

    endless frabjousity

  253. Trolling? by FaxeTheCat · · Score: 1

    The question is so stupid that the only reasonable explanation I can find for posting it is that it is just trolling.

  254. That would be the most stupid "solution" possible by gweihir · · Score: 1

    Only somebody truly incompetent with regards to the question could advocate such a dysfunctional and dangerous behavior that violates all mathematical rules and expectations. In addition, this person did not even do basic research: For float, such a value already exists, it is called +inf or -inf (dependent of the sign of what you divided) and it is specified in IEEE754.

    I nominate this suggestion "most stupid of the month" and the submitter "don't hire, dangerously clueless".

    --
    Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
  255. Why stop at divide by zero? by dilvish_the_damned · · Score: 1

    Compilers and interpreters have been far too lazy for too long.. It is high time they start doing what we mean, not what we say.

      For instance non-addressable memory access could be quietly replaced with the previous memory access. Memory contents flagged as string could be used in any arithmetic using any base because the result is coerced into int 1, so as to always succeed. Recursive loops should just break out at some point so we can keep moving along into... umm, some other code? (-- seems reasonable).

    Although, I am starting to think that anyone who means for things like that to happen is surely a dick.

    --
    I think you underestimate just how much I just dont care.
  256. Re:When a man is tired of checking for divide-by-z by gnupun · · Score: 1

    That's like saying, "after 20 years of programming, your programs should not have bugs." That's just silly and wrong.

  257. INF versus MAX_INT by Immerman · · Score: 1

    Except that, like NaN (Not a Number), INF propagates meaningfully. Once you get an INF all future calculations using that number can only result in INF or NaN (or possibly 0 after dividing a normal number by INF, depending on the implementation. But that's probably okay).

    MAX_INT/MIN_INT do not share that property, they're perfectly normal numbers at the limits of representation. The only sign you get of an error is that you have inconsistent data. If you have an INF or NaN showing up in your results it's pretty obvious that there's an error somewhere. MAX_INT though - do a little math on it and it will no longer be obvious that there was ever an error, especially if your valid data may be approaching the limits of your integer range.
    Some specific failure cases:
    +INF / +INF = NaN ----- MAX_INT / MAX_INT = 1 (You've just performed an undefined operation that completely removes any ability to make a reasonable approximation, where's the warning?)
    +INF * 0 = NaN ----- MAX_INT*0 = 0 (same problem, you've done something that can't even be approximated, and it just disappears?!?)
    0.0 / 0.0 = NaN ----- 0 / 0 = ??? (again, a completely undefined operation, what should you do?)
    +INF / 7 = +INF ----- MAX_INT / 7 = some perfectly normal number (really!?!)
    +INF + 1 = +INF ----- MAX_INT + 1 = MIN_INT (getting into some pretty esoteric theoretical mathematics to justify that...)

    I agree it would be nice if there were a way to represent +INF, -INF, and NaN in integers, but doing so would greatly complicate integer calculations, which are extremely straightforward in silicon (well, division is a *little* complicated, but not remotely as complicated as floating point addition). And without silicon-level support you'd need to add branching conditionals to EVERY integer calculation, completely killing performance, as well as disrupting lots of traditional integer exploits such as rollover, bitwise operations, and others that are widely deployed as dramatically performance-boosting hacks.

    --
    --- Most topics have many sides worth arguing, allow me to take one opposite you.
    1. Re:INF versus MAX_INT by Anonymous Coward · · Score: 0

      Once you get an INF all future calculations using that number can only result in INF or NaN (or possibly 0 after dividing a normal number by INF, depending on the implementation. But that's probably okay).

      There are more exceptions than that. Arctan(inf) = 90 degrees (or PI/2 radians), and arctan(-inf) = -90 degrees. Which makes sense, as tan(90 deg) = inf and tan(-90 deg) = -inf.

  258. Wow ... by garry_g · · Score: 1

    Please check the appropriate:

    [ ] neither have I any idea what math is about, nor do I care about clean programming
    [ ] what could go wrong?
    [ ] I decided to select "0" as result, because I have no idea how to code the rotated "8" that shows up in them mathy books
    [ ] I'm completely and utterly lazy.

  259. Do your homework by benzh · · Score: 1

    Mathematicians sure are tired of checking for div by 0 for hundreds of years now. Yet they know better than to give in to their primal urges, bc they know what havoc any workaround will wreck in the long run. So do your homework. The needs of the many outweigh the needs of the few.

  260. Re:Absolutely! I usually want "infinity" by gnupun · · Score: 1

    For non-zero/0, infinity is the "correct" answer and anything else will give strange results.

    It is not the correct answer since the correct answer is NaN. It's just a hack to avoid having to write exception handlers for every other line of FP code.

    If we had to do tons of integer division, we would need an integer NaN too.

  261. What I don't get is... by seebs · · Score: 1

    Why does the submitter suggest "zero" as the output for division by zero? How is that a better answer than 23?

    I am pretty happy with the "this is a fatal error don't do it" approach, but if it has to be a number, why on earth would you pick zero? That is the least plausible outcome.

    --
    My blog: http://www.seebs.net/log/ --- My iPhone/iPad app: http://www.seebs.net/seebsfrac/
    1. Re:What I don't get is... by Ihlosi · · Score: 1
      Why does the submitter suggest "zero" as the output for division by zero? How is that a better answer than 23?

      Statistically, returning zero usually yields less horrible consequences than returning an arbitrary non-zero number.

      If the result of the division is used in further calculations, e.g. in a product, a zero won't cause additional undefined behavior by signed integer overflows, etc.

    2. Re:What I don't get is... by SuiteSisterMary · · Score: 1

      Ideally it would throw a trappable exception. If you want x/0 to equal 0, catch the exception and deal with it. Otherwise, crash as expected.

      --
      Vintage computer games and RPG books available. Email me if you're interested.
  262. Try Common Lisp by Anonymous Coward · · Score: 0

    I'm murky on the details, but Common Lisp's "condition" system might help. It's a generalization of exceptions in that you can raise a condition (which is like throwing an exception) and have the handler specify how to continue the bad computation. So you could set a system-wide handler that catches division by zero and declares the result to be zero, and then your program can continue.

    I'm not saying this is necessarily a good idea, but in general, if your question starts with "the programming languages I know don't allow me to do X", then the answer is "Common Lisp".

  263. Re:x/0 does not equal 0. by Anonymous Coward · · Score: 0

    Infinity does not exist.

    I'm sure you can provide some sort of proof for that. While you are at it you can dig up the proof that time continuous.

    Real mathematicians (ie - NOT you) only speak of numbers APPROACHING infinity.

    Something tells me you don't belong to that group either.

  264. Comment removed by account_deleted · · Score: 1

    Comment removed based on user account deletion

  265. Modelling by Spacelem · · Score: 1

    I work as a mathematical epidemiologist, modelling disease spread in populations. In my work there are three cases when I encounter divide by zero.

    1) Disease transmission. Say you have two types of individual, susceptible and infectious, the numbers of which are given by S(t) and I(t), and the total population size is N=S+I. Diseases typically transmits at a rate beta*S*I/N, where beta is the transmission coefficient. What happens when N=0? In this case we want the transmission rate to also be 0.

    2) Poisson distributed random numbers. When events happen randomly at rate lambda, the number of events that occur in a time interval dt is n~Poisson(lambda*dt). When lambda=0, you'd always expect n=0. Strictly speaking the Poisson distribution isn't defined for lambda=0, but the limit as lambda->0 is indeed 0. The GNU Scientific Library, Octave, Matlab, and R all return 0 for Poisson(0), however Julia and Numpy both return an error.

    3) Adaptive tau leaping. If you aren't using fixed tau leaping, then you need to work out how big a time step you can safely take, which requires bounding the relative change in a variable. This is done by dividing the variable size by the expected change in that variable, and finding the time step tau, repeating for every variable, and taking the smallest time step you get. In this case, it is entirely possible that the expected time step is zero, say when the population is at equilibrium. This doesn't mean that nothing is happening (you should also check that the variance is bounded), and so here you absolutely need that divide by zero is infinity, and that infinity is greater than any other number you might find.

    The first two cases are actually undefined (0/0 is mathematically undefined, since you get different answers depending on how you approach the limit), but the desired outcome is clearly zero. The third case is either 0/0 or x/0, but either way you definitely want to interpret the result as infinity.

    In my situation, I just wrote a small function called div0, which I use whenever I expect a divide by zero to occur, and know that I want to interpret that as zero, not infinity.

  266. Numberphile by Anonymous Coward · · Score: 0

    https://www.youtube.com/watch?v=BRRolKTlF6Q

  267. Re:x/0 does not equal 0. by Anonymous Coward · · Score: 0

    Thank you for finally explaining division by zero correctly.

  268. Result by Anonymous Coward · · Score: 0

    How about NaN? Oh wait...

  269. Dividing by Zero should be X by Anonymous Coward · · Score: 0

    I think of dividing by zero the same as dividing by one because in essence you aren't dividing the original number (X) into anything either way.

  270. off the rails by Anonymous Coward · · Score: 0

    Seeing the question I thought there had been a *serious* revelation in mathematics that I hadn't heard about.

    nope. slashdice being dumb. oh well.

  271. Software engineering, not maths or physics. by pr100 · · Score: 1

    Arguments from mathematical or physical theories or axioms miss the point.

    When writing code we need to understand how our code will behave over it's possible inputs. There's nothing inherently wrong with deciding that in a particular bit of code you're going to ensure that "dividing" by 0 gives you 0 (for example), as long as you know what the consequences are for the behaviour of the programs relying on this.

    The reason mathematicians get upset by this is that this is not what is normally understood by division. Division by zero isn't defined. Whatever we do in our programs isn't going to change that

  272. Re:x/0 does not equal 0. by jeremyp · · Score: 1

    They're not in any kind of state to care how many apples they have got, so you can tell them you gave them two apples and then run away.

    --
    All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
  273. Wow by Anonymous Coward · · Score: 0

    20 years of programming, and you think division by zero should be treated as zero? Wow ... I hope I never have the misfortune to encounter any of your software

    1. Re:Wow by Ihlosi · · Score: 1
      20 years of programming, and you think division by zero should be treated as zero?

      ARM thinks that this is valid under certain circumstances and provides an appropriate setting in their CPUs (DIV_0_TRAP).

      Would they do that if it was completely useless?

  274. Re:x/0 does not equal 0. by tristes_tigres · · Score: 1

    No, it's you that are factually wrong. Pick a book on intro calculus or floating-point numerics before spreading your ignorance on public forum.

  275. Re:x/0 does not equal 0. by tristes_tigres · · Score: 1

    > e know that for all numbers, a multiplication by zero will always equal zero

    Not for machine floating point. 0*Inf = NaN, as required by standard IEEE 754

  276. Re:x/0 does not equal 0. by tristes_tigres · · Score: 1

    You know, your aplomb is actually quite amazing, given your degree of ignorance. I bet you failed your freshmen calculus.

  277. Argghhhhh ! by Sam+Nitzberg · · Score: 1

    I just checked the date to see if it is April First.
    Unfortunately, it's not.

  278. OpenVMS Used to do this by Anonymous Coward · · Score: 0

    I work with an OpenVMS operating system as one of my primary job requirements. We upgraded from V.x to 8.1 a few years back, and found out the hard way how many times 40 year old data analysis software could try to divide by zero. The old FORTRAN compiler used on 7.x would default a Div-By-Zero to a value of zero, which is not the best answer, but at least doesn't crash the software used to power a large, expensive, and critical test facility. When you are dealing with measurement data coming from a test article, the results don't always fall into clean buckets, and finding out that an unexpected zero was measured and crashed the system (remember, FORTRAN doesn't have a good syntax for try and catch) at a high energy case was a very big deal.
    A lot of time and effort was required to go back through the software written over 40 years to try to mitigate MOST of the issues without a complete rewrite.

    In a statically typed language like FORTRAN, replacing a div/0 as a character array ("Div/0" or "NaN") as Matlab or untyped languages would does not work, so the usual workaround is to force any case where there is a div/0 to a ludicrous number that is clear (usually something like 999.999, 987.654, etc...)

    If some languages had a default for this that was consistent, at least you could go back an examine the data afterwards to determine what caused the issue (or if, by some stroke of chance the 999.999 was a real answer). The right thing would be to rewrite all of the old software with these pieces of code in them, but there is never budget for that, or time and resources even if the money is there.

  279. I'd rather a large number... by wardrich86 · · Score: 1

    I Would rather it equal some impossibly large number to make the error quicker and easier to spot.

  280. Tired of checking for divide by zero? by Anonymous Coward · · Score: 0

    IT IS A BUG! Fix your fucking bugs. It seems you are tired of programming. Go work at a McDonalds.

  281. Re:x/0 does not equal 0. by Anonymous Coward · · Score: 0

    OK, fine. *YOU* tell the IEEE-754 floating-point committee that +/- infinity doesn't exist. I'm sure they'd love to correct the standard to remove representations of those two values.

  282. This is a great idea! by DickBreath · · Score: 1

    But instead of a system-wide setting, as you suggest, I would propose an Organization-Wide setting so that by gope policy, all computers in the organization could bet set such that div by zero results in zero! Bravo! (Or maybe a country-wide setting dictated by congress? Or a world wide global setting dictated by congress?)

    In addition, I am tired of checking for File Not Found errors. When the file can't be found, why not just reformat the drive and create the file for me automatically!

    --

    I'll see your senator, and I'll raise you two judges.
  283. Yep, there's lot of uses for non-zeros div-by-0s by rvivekabr · · Score: 1

    Errors are something you better get handled, but if you're uninspired, you can create your own math system like J. A. D. W. Anderson did on his paper "PERSPEX MACHINE VIII: AXIOMS OF TRANSREAL ARITHMETIC". source: http://www.bookofparagon.com/M...

  284. 800 post and no-one talked about Nullity by JigJag · · Score: 1

    Some teacher in the UK came up with this new concept:
    http://www.bbc.co.uk/berkshire...

    probably was discussed on /. already, but too lazy to look it up!

    --
    "The hallmark of humanity is the ability to move beyond sensory inputs" - Mary Helen Immordino-Yang
  285. Invariably bad code in my case by linear+a · · Score: 1

    In my case at least, if there is a div0 in there somewhere then it's invariably a mistake that I need to correct. I'd prefer that the compiler or SDK barf on it or warn me. Philosophically, I suppose I'd prefer that the production code barf as well instead of managing to zoom past some bad logic.

  286. Can't we all just get along? by NotQuiteReal · · Score: 1

    After decades years of living, I've decided I'm tired of the uncertainty of what happens when I die. Would there be any serious harm in universal consensus that said being dead equals zero? Maybe it exists already, not sure. But I run into it all the time in every religious person I've worked with. Does anyone want what happens when they die to result in anything other than zero?

    As long as you are making up shit, you can make up whatever you want, but it doesn't make it true.

    --
    This issue is a bit more complicated than you think.
  287. Re:x/0 does not equal 0. by mark-t · · Score: 1

    There are several well known proofs that division by 0 is undefined, such as treating division as multiplication by the multiplicative inverse, much as addition as adding the additive inverse, which I mentioned above. If you are partial to calculus (actually, this is precalc-level stuff), another relatively straightforward proof is to consider the limit of division by some number x as x approaches 0 from the positive side vs division by x as x approaches 0 from the negative side. The two limits both have a magnitude of infinity, but are of opposite sign. This means that there is a discontinuity in division by 0, and because there are no mitigating factors in a division operation that suggests that only one of the limits would actually be correct at that value, mathematically it is undefined. For the case of 0/0, consider that the limit of 0/x as x approaches 0 is quite well defined, being 0, and the limit of x/x as x approaches 0 is also well defined, being 1. However, again there are no mitigating factors that suggest only one of these limits would be correct, so this means that you still have a discontinuity at 0, and in absence of any particular reason to choose one limit over the other at 0, that means that expression is undefined as well.

    So no.... I am not factually wrong about this.

  288. Zero doesn't exist except as an abstract concept by Anonymous Coward · · Score: 0

    I've been saying this for years: There's no such thing as "real" zero. It's as abstract as infinity. If you probe the vaccuum of space for anything truly empty, you find virtual particle pairs, because there can't be "nothing". I realize that means that the number of battleships sitting on your hand is not zero, but with quantum probability, I'm demonstrably correct (battleships being abstracts for a group of atoms arranged a certain way).

    If you divide by zero, you should get a high random number. I think that's the best a computer could do to rendering reality.

  289. Re:x/0 does not equal 0. by mark-t · · Score: 1

    D'oh.... stupid freudian typo... didn't notice until after I had submitted.

    What I meant in my first sentence above was this:

    ... treating division as multiplication by the multiplicative inverse, much as treating subtraction as adding the additive inverse...

  290. So much fail on /. by myowntrueself · · Score: 1

    I've rarely seen such crap posted on /. pretending to be knowledgeable.

    If x/0 = some constant, whatever that constant might be whether infinity, zero, 8 or whatever, you get this:

    x/0 = c = y/0 therefore x = y for all numbers.

    So all numbers are equal and mathematics completely breaks down.

    divide by zero is UNDEFINED and in programming languages should trigger an exception or error which should be handled in whatever way is appropriate in that program.

    --
    In the free world the media isn't government run; the government is media run.
  291. Re:x/0 does not equal 0. by myowntrueself · · Score: 1

    If x/0 = some constant, whatever that constant might be whether infinity, zero, 8 or whatever, you get this:

    x/0 = c = y/0 therefore x = y for all numbers.

    So all numbers are equal and mathematics completely breaks down.

    --
    In the free world the media isn't government run; the government is media run.
  292. Re:x/0 does not equal 0. by myowntrueself · · Score: 1

    No, it does not equal infinity.

    The Limit as x aproaches 0+ of a/x = infinity.

    But the Limit as x approaches 0- of a/x = negative infinity.

    because this represents a jump-discontinuity, the value of a/0 is just plain undefined.

    This is like week-1 of high school precalc shit. Come on.

    Its even simpler than that

    If x/0 = some constant, whatever that constant might be whether infinity, zero, 8 or whatever, you get this:
    x/0 = c = y/0 therefore x = y for all numbers.

    --
    In the free world the media isn't government run; the government is media run.
  293. Re:x/0 does not equal 0. by tristes_tigres · · Score: 1

    Well, I am sorry, but you are factually wrong about this. Your "proofs" show that division by zero may be undefined for some cases, which does not change the fact that it is quite well defined for some other cases. IEEE 754 is quite clear on that too. You may wish to eduacte yourself beyond pre-calc before sounding off.

  294. Errors are good by ssam · · Score: 1

    From a scientific simulation point of view the worst possible outcome of a simulation is a result that looks plausible but is in fact wrong. I'd much prefer my program to halt or crash, so that I can start to look where the bug is.

    Yes sometimes its a pain. Say I want to measure the velocity by looking at the time taken to cross some region, and sometimes I have zero length regions. Yes i'll get an error, headdesk and add a suitable check. But it will take knowledge of the problem to work out if I should just not report a velocity for that region, or maybe assume it is the same as the previous one, or average the previous and next. If the expression just returned 0 (or 1 (seen as x/x=1)), and that happened to be within the range of plausible values, then it could take weeks or months to spot the issue.

  295. Re:Use a language that doesn't require you to chec by david_thornley · · Score: 1

    In C++, the result of division by zero is undefined, so the implementation can do whatever it pleases and be in accordance. Whether it throws an exception, returns 42, or loads your hard drive with kiddie porn and emails the FBI, is not a matter covered by the Standard. Check the documentation for your implementation (it doesn't have to be there, since this is not implementation-defined but undefined), or simply DON'T DO THAT.

    --
    "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  296. Re:When a man is tired of checking for divide-by-z by geminidomino · · Score: 1

    Weird, I didn't know that the Unseen University HAD a CS department.

    I always figured Mr. Stibbons was just a Tenured Graduate Student.

  297. I want the error. by Tighe_L · · Score: 1

    Why would I want a incorrect answer?

  298. Rounding already sacrifices associativity by tepples · · Score: 1

    Assuming 0/0=1 gives you inconsistent outcomes unless you're willing to sacrifice associativity of multiplication and division.

    Rounding of floating-point multiplication and integer and floating-point division already sacrifices associativity. See legendary a*a*a*a*a*a question on Stack Overflow.

    1. Re:Rounding already sacrifices associativity by khallow · · Score: 1

      Rounding of floating-point multiplication and integer and floating-point division already sacrifices associativity.

      Even when doing infinite precision calculations, which don't normally make a sacrifice of associativity, the problem persists.

  299. Why do stupid people's questions get posted? by Anonymous Coward · · Score: 0

    If you answer that question for me, I'll answer yours.

  300. All these pesky exceptions! Here's the solution: by Lord+Crosis · · Score: 1

    I can save you even more time dealing with exceptions. I have started writing all of my methods in a pattern as follows:

    public void DoSomething (object doItToMe)
    {
            try
            { // Do something here!
            }
            catch { // No-op
            }
    }

    Now I never have to deal with exceptions of any kind!

  301. another illustration of 0/0 issue by ABZB · · Score: 1

    division can be defined as: For a given X,Y X/Y = Z is equivalent to Find a Z such that Z*Y = X If Y is 0. then any value of Z works - so any division by 0 has infinitely *many* solutions - 0/0 is different only in that convenient things can happen with regard to limits of functions and stuff like that.

  302. Ask Slashdot troll? by ilsaloving · · Score: 1

    I mean, really. Unless something has fundamentally changed in mathematics since I was in school, dividing a number by zero is *undefined*. It doesn't make sense.

    If your code is generating divide by zero errors, then you are doing something wrong. Period.

    If you are so lazy or intellectually bankrupt that you can't handle that, then you shouldn't be programming computers.

    1. Re:Ask Slashdot troll? by The_Dougster · · Score: 1

      In calculus, you have a few cases. Generally to handle it you take the limit as your variable approaches zero.

      This typically results in positive or negative infinity depending on from which direction you approach, or undefined (NaN) for 0/0.

      Think of the tangent function.

      --
      Clickety Click ...
  303. Please! by Anonymous Coward · · Score: 0

    OK, as a programmer who frequently has to test for 0 before dividing because he also frequently forgets and discovers stupid bugs.... I would LOVE it if there was a default value, or several.

    The stuff I'm working with now has a lot of math and a lot of division, and mostly the values are all between 0 and 1 or -1 and 1. Quite a lot of the stuff I use does divide one of these variables by another. I have to check for 0 all the time, and it's always obvious to me what the value should be in that circumstance, so I make an if statement to take care of it. It will be a continuous plot basically, of values from 0 to 1 doing other stuff with values from 0 to 1, and I will always hit those boundaries at some point.

    So this makes me want specific operators that would produce certain default values when dividing by zero. Like a "/0" operator that means replace with 0 if it's any kind of infinity or not-a-number (or /1, etc.). It seems like this would not be that hard to do in the floating point hardware, giving multiple ways to divide, each with its own boundary conditions and defaults. Hell, it might exist already. The last time I knew most of my computer's opcodes was in about '98. :)

  304. Exceptions in a map function by tepples · · Score: 1

    The problem here is that many familiar languages treat try as a statement, not an expression, so you can't catch in a sub-expression and produce a result that continues the expression's evaluation.

    Another way of putting it: How should the result of a map() function represent exceptions? If you're not familiar with it, map() takes a callback function and a sequence (such as a list), calls the callback function on each element of the sequence, and returns a new sequence of the function's return values. For example, map(toupper, "Hello world") would produce something analogous to "HELLO WORLD". But if the callback function can throw, how would map() handle cases where some calls throw and others do not?

    1. Re:Exceptions in a map function by Samantha+Wright · · Score: 1

      I think that just means you're a zealot of functional programming; your expectations are wrong. If the language isn't fully functional in nature, don't expect key patterns like map() to work elegantly. They're hacks at best and not really part of the core language design; this is excellent proof of that.

      --
      Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
  305. Proof that 1=2 by allonoak · · Score: 1

    I'm surprised no one has mentioned this yet, but allowing that x/x can be simplified is dangerous ground because it allows us to prove equalities that are not true. (From another standpoint, then, we can prove by contradiction that x/x does not work for x=0.) For reference, consider the following site about the proof that 1=2. https://www.math.toronto.edu/m...

  306. Proof that 1=2 is based on simplifying x/x by allonoak · · Score: 1

    I'm surprised no one has mentioned this yet, but allowing that x/x can be simplified when x=0 allows for strange equalities to emerge, basically that 0=1 or that 1=2. (This also serves as a proof by contradiction to the ability to simplify x/x for x=0) Consider the following reference: https://www.math.toronto.edu/m...

  307. Re:x/0 does not equal 0. by Anonymous Coward · · Score: 0

    Pfft. Just draw a line from negative infinity to positive infinity. Where does it cross the x axis? At 0.

  308. It's been zero every time I've encountered it by oldestgeek · · Score: 1

    If 1/0 = infinity then 0 * infinity = 1 and
          2/0 = infinity then 0 * infinity = 2 etc ad nauseum through all the numbers

    What is wrong with this (algebraic) picture?

    1. Re:It's been zero every time I've encountered it by jbolden · · Score: 1

      What's wrong is that 0*infinity is undefined the same as 0/0. It has no single value as your example shows.

  309. Lazy by Anonymous Coward · · Score: 0

    Division by 0 isn't allowed and the programmer needs to decide what the action should be. Do you indicate that the input is invalid? Do you display nothing for result and and results derived from the division by 0? There should be no default. Don't be lazy.

  310. Re:x/0 does not equal 0. by mark-t · · Score: 1

    Well, I am sorry, but you are factually wrong about this. Your "proofs" show that division by zero may be undefined for some cases, which does not change the fact that it is quite well defined for some other cases. IEEE 754 is quite clear on that too. You may wish to eduacte yourself beyond pre-calc before sounding off.

    Not that it probably matters to you, since it is evident that you are wholly unwilling to listen to people who actually do have an education on the matter, but I have far more math education than just precalculus. The proofs that I've offered or referred to can be independently verified, if you are so inclined to follow up on that, but if you are either unwilling to take the word of people with a significant amount of mathematical training or background, and are evidently unwilling or unable to understand them yourself, and why they would apply to division by zero for absolutely all cases, then all you are really doing is blindly contradicting what I'm saying without even making an an attempt to understand the reasoning behind it. I had up until this point assumed that you weren't deliberately trying to troll people who know what they are talking about, but I am beginning to rethink that assumption.

    For what it's worth, IEEE 754 doesn't determine what is mathematically true, and the only "value" that makes any sense for division by 0 is something that is not a number in the first place, which mathematically is undefined.

  311. On Error Resume Next by Anonymous Coward · · Score: 0

    Or VB with on error resume next

  312. NAN (Not a Number) by PeterJFraser · · Score: 1

    IEEE floating point has NAN. I have always liked it. 0/0 gives it as a result. Calculating a value and seeing that the result is NAN is often cleaner code then checking each variable for zero first. It would be nice if integral arithmetic had something similar but it is not going to happen.

    1. Re:NAN (Not a Number) by jbolden · · Score: 1

      It can in better type systems and those exist today (example "safe division via. the Maybe monad") You can have a NAN added to the integers ( but then your integral math code can't execute directly on the arithmetic logic unit in the CPU, it becomes an abstract type. For higher level languages that often won't matter anyway.

  313. Simplify and conquer: X*0 or X/0 equal X by Mr_Nitro · · Score: 1

    I propose this solution, in the castle of math it just means switching a couple of different special cases, nothing more. But it certainly makes more sense. You are multiplying or dividing by a non quantity, thus you are not performing the operation and your X remains the same. Simple as pie. Another example of math confusion is including 2 in the prime number sequence. It's a mistake performed only to abide to preexisting dogmas. 2 is clearly an even number, the correct sequence is 1,2,3,5... etc. /end rant

  314. Interrupt by Anonymous Coward · · Score: 0

    I use 0/0 to create an interrupt which stops execution.

  315. Re:x/0 does not equal 0. by Verdatum · · Score: 1

    I mean, it's gonna take me awhile to finish drawing this infinitely long line, but so far, it is touching the x access at every single point within the the set of real numbers.

  316. Why 0/0 = 0^0 = 1 in practice by tepples · · Score: 1

    The fact remains, however, that defining 0/0 or 0^0 as 1 is useful in more cases than not 1. See the short explanation or the long explanation.

    1. Re:Why 0/0 = 0^0 = 1 in practice by khallow · · Score: 1

      What fact? I've been in math a while and I have yet to run into anyone who does that in practice. And 0/0 = 1 is a stronger restriction than 0^0 = 1 (because the latter expression has better asymptotic stability, such as considering (ax)^(bx) versus (ax)/(bx)).

  317. Yes, and here is why. by Shaitan · · Score: 0

    People will get all stuck on what is mathematically correct. They are missing the point. The point is what happens in my program and for that we need to go to the parent of math. Mathematics are a system of logical abstraction. If I have two coconuts and take one away I have 2 coconuts, logically the same must be true of apples or oranges or fingers and therefore I can predict results using my fingers.

    Here is my hypothesis. Anything divided by itself is one. Anything divided by one is itself. Anything divided by nothing has not been divided at all and therefore is unchanged. In kind, the reverse is true, anything multiplied by 0 has not been multiplied and therefore is unchanged. Let's look and see.

    Multiplication is addition. Division is subtraction. Let's start with multiplication and show the addition.
    2*2 = 4
    0+2+2 = 4
    Why the zero? Because the second number in multiplication is shorthand for a sequence of +x repetitions. Since this is our first operation, the zero represents the value we had prior to the first operation.

    2*1 = 2
    0 + 2 = 2

    2*0 = 0
    0 = 0
    As I mentioned above. Prior to the operation we had a value of zero, now we still do.

    What about 0*2*3?
    This is two operations.
    0*2*3 = 0
    0+0+0 = 0 (first zero is the starting value)
    0*3
    0+0+0+0 = 0

    What about 2*3*0? Does it break things due to a starting value?
    Again, two operations.
    0+2+2+2 = 6
    6*0 = 0
    0 = 0
    Still no. Every sequence of multiplications is broken into individual multiplications and the starting value is ALWAYS 0.

    Now for division. In division we do something different. We are chopping something up into slices. Whereas multiplication is an operation that always starts with 0. Division is an operation that can start with anything.

    6/2 = 3 pieces of 2
    6/1 = 6 pieces of 1
    6/0 = 6

    6/1 and 6/0 may give the same result but there IS a difference. Let's say we have a pile of skittles and I counted them by 1's. I've pulled 6 skittles out, one by one, and ended with a pile of 6 skittles. That is 6/1. Now let's say we have a pile of 6 skittles and don't pull any out. That's 6/0.

    Multiplication is a repeated sequence of additions, zero either means you are adding nothing or that the number of additions to make is 0, thereby leaving something untouched those are two different things but both result in 0. Division is taking something and splitting it apart. 0 either means you are starting with nothing or you are indicating not to divide it at all. Thus 0/0 = 0 and 0 * 0 = 0.

    Just my 2 cents.

  318. If you're that fucking lazy ... by Anonymous Coward · · Score: 0

    ... you need to get out of programming.

  319. Zero cake is a lie by Duggeek · · Score: 1

    Courtesy of the logic of GLADOS...

    1. You have a cake.

    2. You have to divide the cake to serve it.

    3. Count the number of humans that will get cake. (set to 0)

    4. Divide the cake into equal slices for each human.

    Conclusion: The cake is a lie. Q. E. D.

    Div/0 will always be "a lie", because even if you do substitute an infinite value (the closest "irrational" answer) and return a result, the function becomes useless. Infinity is symbolic, it doesn't actually exist, because there's no rational way to express it, let alone apply it to a process. It's an endpoint, not a step.

    tl;dr -- Stop using such reckless floating-point math and improve your exception handlers. (maybe even validate input... I know; shocking.) It's not that difficult when (or if) you plan your projects in advance.

    Either that, or write your own function for division that traps div/0 and returns a zero for you, then substitute it in for every '/' in your code. Good luck debugging that.

    --
    This post © Copyrite Duggeek, all rights reversed.
  320. Apoogies for being snarky but ... by FreedomFirstThenPeac · · Score: 1

    This question shows why we don't want English majors cross-training into programming. :-)

    --
    "There is no god but allah" - well, they got it half right.
  321. Twenty Years of Writing Code by Pherdnut · · Score: 1

    And THIS is what keeps you up at night?

  322. To lazy to check? by Anonymous Coward · · Score: 0

    I've decided I'm tired of checking for div by zero.

    Oh come on, it's not that difficult, pick a default value (say zero) and use it in your own code.

    IF X not equal 0 THEN Y=Z/X ELSE Y=0

  323. I get the feeling this question comes from a troll by harryg123 · · Score: 1

    subject says it all

  324. this is a joke, right? by gzuckier · · Score: 1

    I'm not even happy with the inaccuracy from converting integer math to floating point.
    http://ta.twi.tudelft.nl/users/vuik/wi211/disasters.html

    --
    Star Trek transporters are just 3d printers.
  325. Re:x/0 does not equal 0. by gzuckier · · Score: 1

    Math is not expressive enough to handle the real world, since division by zero can occur without causing a problem. Example: you want to divide apples among people. You have one apple and two people, each person gets half an apple. You have one apple and no people, no one gets the apple. In the real world there is no problem with this reasoning, it's only that math fails to handle it so you have to include extra code to make it come out. In a real life situation, you need no extra error-handling because there is no error. In conclusion, math fails to express the natural world.

    Let's deliver one apple for each infinitesimal fraction of a person. (Having fractional people instead of integers here is not unrealistic; say a government declares a law that apples are to be distributed to the population such that there is one apple given for each tenth of a person). Then each person gets a really huge number of apples. Let's deliver one apple for each 2 infinitesimal fractions of a person; now each person gets half as many apples. 3 fractions, 1/3 of that huge number, etc. Hey, let's go the other way, from one apple per 1 fraction to 1 apple per zero; we know what the curve we've just plotted suggests. but you're saying it should be zero? no thanks, I prefer my math without arbitrary discontinuities and singularities.

    --
    Star Trek transporters are just 3d printers.
  326. Re:x/0 does not equal 0. by gzuckier · · Score: 1

    No, it does not equal infinity.

    The Limit as x aproaches 0+ of a/x = infinity.

    But the Limit as x approaches 0- of a/x = negative infinity.

    because this represents a jump-discontinuity, the value of a/0 is just plain undefined.

    This is like week-1 of high school precalc shit. Come on.

    But +0 = -0 ; yet 1/(+0) does not equal 1/(-0) ... Omigod everything we know is wrong. AAAAAAAAHHHHHHH! Does not compute! Danger Will Robinson, Danger! Fzzt! (Thud)

    --
    Star Trek transporters are just 3d printers.
  327. Re:x/0 does not equal 0. by gzuckier · · Score: 1

    Infinity does not exist. Real mathematicians (ie - NOT you) only speak of numbers APPROACHING infinity. So, as the divisor approaches zero, the quotient approaches infinity. You cannot have infinity as a quantity since it does not exist. Otherwise what happens when you divide infinity by zero, and is that new infinity the same as the first infinity?

    If infinity does not exist, for mathematicians, then how many integers are there? And how many points exist between 1.0001 and 1.0002 on the number line?

    --
    Star Trek transporters are just 3d printers.
  328. Maybe Monad and divisor types by jbolden · · Score: 1

    The issue is your type system sucks. What you want are types that guarantee they are non-zero.

    So what you want is a type "divisor double" or "divisor integer" where putting a 0 in such a variable generates a type error.

    A more sane approach to ignoring the type avoid the error checking you want would be to have this defined using the maybe Monad. Then you could just define

    div' takes 2 numbers of types A and returns a Maybe A where
    div' x y = if y != 0
          then Just (div x y)
          else Nothing

    Programs then automatically lift
    if f takes type B to type C then
    f' from Maybe B to Maybe C becomes
    f' Just (b) = Just (f b)
    f' Nothing = Nothing

    etc... Then you get rid of the division by 0 when it makes sense. If you want to cast Nothing to 0 (which I think is dangerous) do it explicitly at some point where you don't want a Maybe object but insist on a base object. You can't change math, but at least it makes the call explicit.

  329. Exceptions in Python list comprehensions by tepples · · Score: 1

    Then let me rephrase in a language that isn't Haskell.

    How should the result of Python [some_expression_involving_x for x in some_sequence] represent both values of the expression and exceptions raised during other evaluations of the expression? For example, in a CSV processing, I'm tempted to use [headings.index(x) for x in wanted_cols], but that brings down the whole sequence if even one element of wanted_cols is not present in headings.

    1. Re:Exceptions in Python list comprehensions by Samantha+Wright · · Score: 1

      Same reply: Python is not fully functional, and so list constructors like that cannot be counted upon to work elegantly in all situations. This is a completely normal thing common to basically every imperative language, and it's just something you have to accept—and write a special-purpose function for.

      --
      Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
  330. Big Problem by Anonymous Coward · · Score: 0

    That would make debugging much more difficult! While defensive programming is good, being too defensive and not even letting the programmer know when something terrible happened would make debugging very difficult. Imagine if instead of throwing an IndexOutOfBounds Exception Java just returned the last thing in the list. While the program would run it would probably not return the right result. In general, if you divide by zero you screwed up. You probably don't want zero as an answer and there is probably some underlying bug in your program. It would be much more difficult to find that bug if your program just pretended everything was ok. Whereas if it throws a Nan or whatever you know "Oh this value is zero when it shouldn't be". Maybe in very specific cases you would want to have it just set the result to zero. In games for instance you would want the game to try to continue to work, albeit slightly incorrectly, instead of just dying. But forcibly always setting divide by zero to zero system wide would make debugging much more diffficult!

  331. How would you invert the operation? by Anonymous Coward · · Score: 0

    x * 0 = 0. So divide both sides by 0, and you have x = 0/0, which is nonsense - but reveals something: x * 0 = 0 for all x such that x is a real number. So literally, there could be any answer to the question, "What is 0/0?". This is why it's undefined.

  332. Div by zero is undefined by Anonymous Coward · · Score: 0

    Division by zero is undefined. It is an error if it occurs and should be catched. If you allow division by zero, your math is wrong. You can prove whatever you want. Look:

    7 * 0 = 17 * 0
    now divide by zero, and you get:
    7 = 17 which is clearly false. The solution is to forbid division by zero.

  333. When I get a divide-by-zero, I want ... by RockDoctor · · Score: 1

    Does anyone want their div by zero errors to result in anything other than zero?

    I want a divide-by-zero error that occurs in properly validated data to result in a HCF command being carried out.

    Further more, I want people writing code for me to actually understand what they're doing, and to analyse their algorithms so that they check data going in, and trap for errors. Yes, it's time-consuming and difficult. But it's also necessary.

    --
    Birds are not dinosaur descendants;birds are dinosaurs, for all useful meanings of "birds", "are" and "dinosaurs"
  334. John by Anonymous Coward · · Score: 0

    If in your problem domain it makes sense for 0/0 = 0, then write a function that does that. I think it's fair to say that for most of us, that isn't a good solution. Remind me why you're bothering the world with this again?

  335. Strange understanding of math by allo · · Score: 1

    1/1 = 1
    1/0.1 = 10
    1/0.00001 = 10000 ...
    1/0 = 0

    erm, okay. graph that function and ask yourself, can this be right?

  336. Re:x/0 does not equal 0. by Anonymous Coward · · Score: 0

    Infinity does not exist. Real mathematicians (ie - NOT you) only speak of numbers APPROACHING infinity. So, as the divisor approaches zero, the quotient approaches infinity. You cannot have infinity as a quantity since it does not exist. Otherwise what happens when you divide infinity by zero, and is that new infinity the same as the first infinity?

    "No one shall expel us from the Paradise that Cantor has created."
    -- David Hilbert

  337. Apologies to The Far Side... by dogsbreath · · Score: 1

    I calculate

    You check for div by zero

    Is that too complicated for you Carl?

  338. Projecting to infinity by tepples · · Score: 1

    Say I'm doing texture mapping of a flat plane parallel to the X axis, where world_Z = k/screen_Y. Above and below the horizon, Z is valid. But at the horizon, Z would be infinity. In this case, defining 1/0 as INT_MAX would produce an acceptable display.

  339. Ignoring bus errors on 8-bit processors by tepples · · Score: 1

    If you are dividing by zero YOU ARE DOING IT WRONG.

    Say I'm projecting a floor plane (one parallel to the X-Z axis) onto a screen. For any given Y coordinate on the screen, the distance to this plane along Z is proportional to 1/Y. At the horizon, Y is 0, and the distance becomes infinite. The result of this division thus ought to approximate infinity.

    You might as well just ignore bus errors as well.

    Plenty of 8-bit microprocessors do just that, leaving the last byte of a load instruction on the bus that the load instruction ends up reading due to capacitance. In one project I've made, I use this open bus behavior to enumerate attached peripherals.

  340. Taxicab geometry by tepples · · Score: 1

    In non-Euclidean taxicab geometry, the perimeter of the set of points of distance 1/2 from a given point does equal 4.

  341. Division Has A Meaning by Jaborandy · · Score: 1

    Your code that does division probably does that because division has a meaning, and you need that meaning. Trust me and everyone else here who knows math: the meaning you want does not include the case where you are dividing by zero. Dividing by zero is nonsensical in code and in life. So what went wrong with your program to get a zero into the denominator? That's the issue in your program. Is there a place where you can check user inputs to make sure they aren't insane? Is there a place where you're calculating what is supposed to be a very small number but sometimes it rounds down too low and makes your number zero by accident? Put the check there. Are you measuring or counting something that can legitimately be zero? I bet the division scenario doesn't apply in that case. Check for zero and do what does make sense. Fix your program.

    --Jaborandy

    1. Re:Division Has A Meaning by Ihlosi · · Score: 1
      Put the check there.

      Depending on your platform, putting the check there might interfere with CPU load/latency constraints (and using a bigger CPU might interfere with power/cost constraints), while having the CPU just return zero as the result of division by zero can be handled later (when it doesn't interfere with CPU load/latency).