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?

698 of 1,067 comments (clear)

  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: 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.

    3. 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.

    4. 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.

    5. 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...
    6. 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.

    7. 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.

    8. 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?

    9. 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.

    10. 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.
    11. 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.
    12. 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.

    13. 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
    14. 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
    15. 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.

    16. 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.

    17. 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.

    18. 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!)

    19. 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.

    20. 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?

    21. 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 ;)

    22. 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.

    23. 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.
    24. 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).

    25. 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.

    26. 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
  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: 1

      Bad question. There is no percentage.

    2. 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.

    3. 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.

    4. 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.)

    5. 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.

    6. 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.

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

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

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

      Example?

      --
      I'm bad with sayings, so just go live life for crying out loud.
    9. 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.

    10. 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.

    11. 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.
    12. 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.
    13. 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).

    14. 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.

    15. 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
    16. Re:Simple by tristes_tigres · · Score: 1

      Eigenvalue finding by bisection using Sturm sequence.

    17. 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.

    18. 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).

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

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

    20. 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 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.
    5. 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.

    6. 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?"

    7. 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.

    8. 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
    9. 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.
    10. 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]
    11. 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.)

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

    Umm, wtf is this shit?

    1. 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 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
    7. 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.

    8. 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.

    9. 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...

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

      But programming is haaaard!

      Let's go shopping!

    11. 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.

    12. 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.

    13. 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.

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

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

    15. 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
    16. 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.

    17. 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.

    18. 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.

    19. 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
    20. 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
    21. 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.

    22. 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. 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. :/

  7. 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 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.

  8. 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 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.

    3. 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

    4. 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.

    5. 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.

    6. 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

    7. 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.

    8. 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.
    9. 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.

    10. 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."

    11. 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.
    12. 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.
    13. 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/
    14. 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

    15. 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
    16. 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.

    17. 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...

  9. 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?

  10. 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.

  11. 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 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.

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

      Mathmatically both are [as] correct and everything inbetween.

    8. 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
    9. 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.

    10. 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!
    11. 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.

    12. 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.

    13. 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
    14. 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).

    15. 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.

    16. 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.

    17. 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?
    18. Re:Infinity by Darinbob · · Score: 1

      No finite number is closer or farther from infinity.

    19. 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.

    20. 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.
    21. Re:Infinity by Quirkz · · Score: 1

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

    22. 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.
    23. 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
    24. Re:Infinity by Dunbal · · Score: 1

      Except a graph of the tangent function.

      --
      Seven puppies were harmed during the making of this post.
    25. 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
    26. 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.

    27. 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.

    28. 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.

    29. 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.
    30. 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.

    31. 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.

    32. 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.

    33. 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.

    34. 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.

    35. 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.

    36. 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.

    37. 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.
    38. 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.

    39. 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.

    40. 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.

    41. 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.

    42. 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.
    43. 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
    44. 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.
    45. 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
    46. 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.
    47. 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.
    48. 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!
    49. Re:Infinity by Verdatum · · Score: 1

      ;) fair enough.

    50. 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.
    51. 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.
    52. 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.

    53. 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.

    54. 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.

    55. 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."
    56. Re:Infinity by HuguesT · · Score: 2

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

    57. 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.

    58. 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.

    59. 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.
    60. 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.

    61. 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?

    62. 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.

    63. 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.

    64. 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.

    65. 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.

    66. 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.

    67. 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.

    68. 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.

    69. 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'.

    70. 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).

    71. 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.

    72. 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!
    73. 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.

    74. 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
    75. 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.
    76. 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
    77. 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)

    78. 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.

    79. 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.

    80. 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!

    81. 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."
    82. 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.
    83. 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.
    84. 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.
    85. 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.

    86. 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.
    87. 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.....
    88. 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.
    89. 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.....
    90. 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
    91. 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!)

    92. 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.

    93. 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.
    94. 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".

    95. 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!!!"
    96. 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.

    97. 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!!!"
    98. 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.
    99. 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
    100. 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.

    101. 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!!!"
    102. 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.

    103. Re:Infinity by darkHanzz · · Score: 1

      There's NaN (not-a-number) for that. works beatifully

    104. Re:Infinity by Hognoxious · · Score: 1

      Grammatically that doesn't make sense.

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    105. 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.
    106. 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!
    107. 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.
    108. 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.

    109. 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.

    110. Re:Infinity by inasity_rules · · Score: 1

      Lim as x->0 of X/X =??

      --
      I have determined that my sig is indeterminate.
    111. 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.

    112. 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.

    113. Re:Infinity by BlackPignouf · · Score: 1

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

      Let's pretend you didn't write it, okay?

    114. 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!

    115. 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.

    116. 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.

    117. 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.

    118. 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.

    119. 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.
    120. 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.
    121. 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?

    122. 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.
    123. 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.

    124. 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.
    125. 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!!!!!
    126. 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.

    127. 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).

    128. 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
    129. 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
    130. 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
    131. 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.

    132. 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
    133. 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!

    134. 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?

    135. 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.

    136. 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
    137. 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.. ;)

    138. 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
    139. 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
    140. 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.

    141. 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.

    142. 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?

    143. 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.
    144. 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
    145. 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.

    146. 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.

    147. 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!
    148. 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.
    149. 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!
    150. 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 ;-)

    151. 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!
    152. 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

    153. 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.

    154. 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.
    155. 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

    156. 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.
    157. 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.)

    158. 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.

    159. 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.

    160. 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
    161. 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
    162. 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.

    163. 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
    164. 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.

    165. 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.

    166. 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
    167. Re:Infinity by oldestgeek · · Score: 1

      Infinity is undefined!

    168. 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.
    169. 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.
    170. 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.

    171. 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.

    172. 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.

    173. 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? :)

    174. 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.

    175. 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

    176. 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
    177. 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.

    178. 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.

    179. 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.

    180. 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.

    181. 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"
    182. Re: Infinity by tastyrerun · · Score: 1

      This thread is a good example of why I love /.

    183. 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.....
    184. 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.....
    185. 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.....
    186. 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.

    187. 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.
    188. 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.
    189. 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!
    190. 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..
    191. 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.
    192. 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.
    193. 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."
    194. Re:Infinity by __aabppq7737 · · Score: 1

      every expression can have multiple results, contradictory rules kill both results.

    195. 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

    196. Re:Infinity by __aabppq7737 · · Score: 1

      0 / 0 is the union of all real and non-real numbers

    197. 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.

    198. 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

    199. 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!!!"
    200. 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!!!"
    201. 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.

    202. 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.

    203. 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.

    204. 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.
    205. Re:Infinity by allo · · Score: 1

      Infinity like java knows it is okay. this constant obeys the usual rules like inf + x = inf

    206. 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}"

    207. Re:Infinity by allo · · Score: 1

      math gives you two limits, one being 0, one being 1.

    208. 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

    209. 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
    210. 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
    211. 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!
    212. 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

  12. When a man is tired of checking for divide-by-zero by Anonymous Coward · · Score: 3, Insightful

    ... he is tired of life.

  13. 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 tristes_tigres · · Score: 2

      Nope. Division by zero is NaN if and only if the numerator is zero as well.

    7. Re:Math doesn't approve by BradMajors · · Score: 1

      The result of dividing my zero is not infinity.

    8. 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).

    9. 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.
    10. 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
    11. 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."

  14. 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.

  15. 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.

  16. 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!
  17. 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 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.

  18. 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 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.
    8. 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.

    9. 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.

    10. Re:I'm tired, too by tristes_tigres · · Score: 1

      Good example of a wrong way to solve the problem.

  19. It's irrational by Coldeagle · · Score: 1

    And we all know that computers are ALWAYS rational :P

    1. 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?

  20. 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 Fwipp · · Score: 3, Insightful

      No, 0/0 is still undefined.

  21. 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.

  22. 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.
  23. 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
  24. 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.

  25. 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.

  26. 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 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
  27. 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".

  28. 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.

  29. 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 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?

    2. 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.
    3. 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
    4. 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.
    5. 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.
  30. 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.

  31. 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
  32. 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...

  33. 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
  34. 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
  35. 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.

  36. On Error by YuppieScum · · Score: 1

    Resume Next

    What could possibly go wrong?

    --
    This sig left unintentionally blank.
  37. 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!

  38. No by Verdatum · · Score: 1

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

    Yes.

    No.

  39. 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 ...

  40. 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: 5, Funny

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

      Yes.

      No.

      Maybe.

      Maybe not.

      Wrong!

      Pineapple.

    3. 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?
    4. 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.
    5. 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.
    6. Re:Maybe by AK+Marc · · Score: 1

      Aww, I was hoping for "I don't know" followed by "could you repeat the question"

    7. Re:Maybe by the+phantom · · Score: 1

      You're not the boss of me!

    8. 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
    9. 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>
    10. Re:Maybe by scsirob · · Score: 1

      !PHP

      --
      To Terminate, or not to Terminate, that's the question - SCSIROB
    11. 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

  41. 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.

  42. 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?

  43. 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 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.
    3. 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.....
  44. 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.

  45. 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.

  46. 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 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).

    3. 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.

    4. 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.
  47. 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 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.
    2. 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.

  48. 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

  49. 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!

  50. Re:ARM has it by FranTaylor · · Score: 1

    Having a default is fine

    for creating really really horrible, impossible to find, bugs

  51. 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 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
    2. 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.

    3. 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
  52. 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.
  53. 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.

  54. 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.

  55. 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.

  56. Re:sometimes the correct answer is 1 by FranTaylor · · Score: 1

    just like zeno, you will never actually get anywhere with that answer

  57. 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.

  58. 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!
  59. 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 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
  60. 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 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.

  61. 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.

  62. Re:Zero is wrong... by Livius · · Score: 1

    First issue, x/0 mathematically is infinity, not zero.

    Which infinity? There are many.

  63. 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.

  64. 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 redshirt · · Score: 1

      Where are mod points when I need them?

  65. 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.

  66. 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.

  67. Dear Slashdot, math is hard by sideslash · · Score: 3, Funny

    "Can't I just be a programmer and not understand math?"

  68. 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?"

  69. 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.

  70. 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.

  71. Re:Zero is wrong... by FranTaylor · · Score: 1

    Which infinity? There are many.

    I think this counts as an "understatement"

  72. 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?

  73. 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.

  74. 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.

  75. 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.

  76. 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.

  77. 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.

  78. @ OP.... by naturaverl · · Score: 1

    You, sir, are an idiot.

  79. 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

  80. 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".

  81. Sounds like bugs by The+MAZZTer · · Score: 5, Funny

    caused by dividing by zero returning zero.

  82. 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.
  83. 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 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!"

    3. 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)

    4. 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

  84. 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.

  85. 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
  86. 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?

  87. 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.
  88. 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.

  89. 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.
  90. 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.

  91. 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.
  92. 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."
  93. 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!

  94. 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").

  95. 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.
  96. 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.

  97. 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
  98. 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
  99. 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.:)

  100. 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. :-)

  101. 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.

  102. 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.

  103. Re:Idiot by Noah+Haders · · Score: 1

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

  104. 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.
  105. 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.
  106. 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
  107. 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.
  108. 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.

  109. 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.

  110. 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.

  111. 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?

  112. Re:x/0 does not equal 0. by Darinbob · · Score: 1

    Or a +1 Dope Slap button.

  113. "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.
  114. 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.

  115. What's the harm? by TheCreeep · · Score: 1

    You end up in undesirable situations like having a share button on slashdot after each story.

  116. Re:x/0 does not equal 0. by tristes_tigres · · Score: 2

    No he isn't. He is right, too.

  117. 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);
  118. 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.

  119. Re:x/0 does not equal 0. by Darinbob · · Score: 1

    "Well defined" is poorly defined here.

  120. 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.

  121. 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...

  122. 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 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.
  123. 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.

  124. 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.

  125. 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.
  126. 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.
  127. 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.

  128. 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

  129. 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
  130. 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.

  131. 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.

  132. 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?

  133. 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.

  134. 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.

  135. 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?

  136. Comment removed by account_deleted · · Score: 2

    Comment removed based on user account deletion

  137. 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.

  138. 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.

  139. 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.

  140. 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.

  141. 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.

  142. 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.

  143. 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...

  144. 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 ...
  145. 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 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.
  146. 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

  147. 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.
  148. 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.
  149. 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.
  150. 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/...

  151. 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.

  152. 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.
  153. 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...

  154. 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...

  155. 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

  156. Re:No by JustOK · · Score: 1

    File not found. Try sandpaper.

    --
    rewriting history since 2109
  157. 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.

  158. 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
  159. 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)

  160. 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
  161. 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
  162. 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
  163. 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.

  164. 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.
  165. 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.....
  166. 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?

  167. 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
  168. 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.

  169. 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
  170. 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
  171. 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
  172. 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
  173. 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
  174. 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.

  175. 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/....

  176. 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);
      }

  177. 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
  178. 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.

  179. 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?

  180. 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).

  181. 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.
  182. 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.
  183. 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

  184. 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.

  185. 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.
  186. 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.
  187. 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.

  188. 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.
  189. 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.

  190. 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.

  191. 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.

  192. 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.
  193. Comment removed by account_deleted · · Score: 1

    Comment removed based on user account deletion

  194. 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.

  195. 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
  196. 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

  197. 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
  198. 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?

  199. 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.

  200. 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.

  201. 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

  202. 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.

  203. 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
  204. Argghhhhh ! by Sam+Nitzberg · · Score: 1

    I just checked the date to see if it is April First.
    Unfortunately, it's not.

  205. 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.

  206. 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.

  207. 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.

  208. 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.
  209. 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...

  210. 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
  211. 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.

  212. 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.
  213. 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.

  214. 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.
  215. 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...

  216. 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.
  217. 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.
  218. 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.
  219. 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
  220. 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.
  221. 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.

  222. 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
  223. 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.

  224. 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.
  225. 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.
  226. 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
  227. 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.

  228. I want the error. by Tighe_L · · Score: 1

    Why would I want a incorrect answer?

  229. 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.

  230. 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!

  231. 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.

  232. 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 ...
  233. 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!
  234. 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...

  235. 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...

  236. 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.

  237. 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.

  238. 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.

  239. 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

  240. 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.

  241. 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.

  242. 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)).

  243. 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.
  244. 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.
  245. Twenty Years of Writing Code by Pherdnut · · Score: 1

    And THIS is what keeps you up at night?

  246. 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.
  247. 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
  248. I get the feeling this question comes from a troll by harryg123 · · Score: 1

    subject says it all

  249. 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.
  250. 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.
  251. 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.
  252. 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.
  253. 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.
  254. 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.

  255. 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!
  256. 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"
  257. 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?

  258. Apologies to The Far Side... by dogsbreath · · Score: 1

    I calculate

    You check for div by zero

    Is that too complicated for you Carl?

  259. 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.

  260. 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.

  261. 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.

  262. 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)?

  263. 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).