• (cs)

    I think it's a setting on the ATM that allows clients to withdraw only i*n dollars at a time, being i an integer and n the amount of the smallest banknote stored in the machine.

    So, apparently Monty was going to withdraw 40 $ as an infinity of 0 $ dollar bills.

    edit: sorry, pointed out by other poster

  • Dong (unregistered)

    Eve online

  • Daedalus (unregistered) in reply to TopCod3r
    TopCod3r:
    Old Coder:
    TopCod3r:
    There is an EASY way to prevent divide by zero errors, so easy that I am surprised they haven't built it into the .NET framework yet... Simply add 0.000000001 to the denominator. This is such a small number that it makes no significant difference to the result. I like to make a constant, something like this and it works like a champ...

    Const NODBZ As Double = 0.000000001 ...

    X = Y / (Z + NODBZ)

    Then just round it when you are done.

    Riiiight. So, just divide by a very very small number, and your result turns out to be a very very large number, which might cause an overflow exception instead. Very useful.

    Or perhaps, you know, the divide-by-zero exception flags up the fact that there is a bug in the algorithm, and your little add-on just hid it?

    Ever heard of Try/Catch?

    I should have clarified, this solution is for Integers... it becomes a decimal when you add 0.000000001 to it, that is why I said you have to round it back.

    You seem to be assuming that if the program wants to divide by zero, that's somehow okay. If your hair was falling out, would you: a. buy a wig b. see a doctor "it makes no significant difference to the result." YES. If you AREN'T dividing by zero, it won't really affect integers, true. But if Z is 0 (which is the whole point!), you'll be off by a factor of infinity! CAPTCHA: genitus

  • (cs)

    Guild Wars.

    DAMMIT. I did it wrong.

  • Coward_Anonymous (unregistered) in reply to SS

    EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online EVE Online

  • I aint afraid of no troll (unregistered) in reply to Daedalus

    Once again we must all be in awe at the ease in which TopCod3r is able to troll.

    If I had a hat it would be off.

  • Sir (unregistered) in reply to EatenByAGrue
    EatenByAGrue:
    It's not "100 2.04858e+290 growth", it's "100 2.04858e+290rowth".

    I'm not sure what rowth is, but I still don't want 2.04858e+290 of it.

    omg that's OVER 9000 !

  • Monty (unregistered) in reply to Sir

    Hey, this is Monty and while the ATM did present me an unsolvable problem it dispensed my 40 bucks with no trouble. :P

    So unfortunately it's not as simple as the machine running out of money. :P

  • SNF (unregistered)

    What would be really awesome is if the game gave you a stack trace when you select « 3. Could you give me some more details? »

  • (cs) in reply to SS
    SS:
    I swear to God I'm going to pistol whip the next guy who says, "EVE Online."
    You have worn your firearm out while pistol whipping guys saying "EVE Online". Now what?
  • Foobar (unregistered) in reply to TopCod3r
    TopCod3r:
    There is an EASY way to prevent divide by zero errors, so easy that I am surprised they haven't built it into the .NET framework yet... Simply add 0.000000001 to the denominator. This is such a small number that it makes no significant difference to the result. I like to make a constant, something like this and it works like a champ...

    Const NODBZ As Double = 0.000000001 ...

    X = Y / (Z + NODBZ)

    Then just round it when you are done.

    Oh yeah please, let's build that into the .NET Framework, I would really like to see what will happen then.

    I seriously hope you are kidding, but I am afraid you are not...

  • (cs) in reply to Daedalus
    Daedalus:
    JimM:
    Of course, that doesn't really help, because any number is divisible by zero (the result is undefined, but the number itself is divisible by zero)...
    Whut. No. NO.

    How can you claim 4 is divisible by 0, if 4/0 is undefined?

    erm... look -> 4/0

    There, I divided 4 by 0.

    See how easy that was?

  • (cs) in reply to I aint afraid of no troll
    I aint afraid of no troll:
    Once again we must all be in awe at the ease in which TopCod3r is able to troll.

    If I had a hat it would be off.

    If I had a hat it would have to have "TopCod3r" on it. That's how much of a fan I am.
  • Stalker (unregistered) in reply to JimM
    JimM:
    Daedalus:
    How can you claim 4 is divisible by 0, if 4/0 is undefined?
    erm... look -> 4/0

    There, I divided 4 by 0.

    See how easy that was?

    Adjective divisible

    (arithmetic) Of an integer, that, when divided by another integer, leaves no remainder.

  • (cs) in reply to Old Coder
    Old Coder:
    TopCod3r:
    I like to make a constant, something like this and it works like a champ...

    Const NODBZ As Double = 0.000000001 ...

    X = Y / (Z + NODBZ)

    ... perhaps, you know, the divide-by-zero exception flags up the fact that there is a bug in the algorithm ...
    No, the DBZ exception indicates that there is a bug in your input - it has no bearing on the correctness of your algorithm. If you are confident that the algorithm is correct I see no problem with handling someone else's inappropriate input in this way...

  • Teller (unregistered) in reply to Kalleguld
    Kalleguld:
    Or maybe a bank teller had just refilled the stock of 0$ bills
    But why would the ATM have complained about Monty's input? It could just have given him an infinite number of $0 bills.
  • More (unregistered) in reply to Zap Brannigan
    Zap Brannigan :
    Old Coder:
    TopCod3r:
    There is an EASY way to prevent divide by zero errors, so easy that I am surprised they haven't built it into the .NET framework yet... Simply add 0.000000001 to the denominator. This is such a small number that it makes no significant difference to the result. I like to make a constant, something like this and it works like a champ...

    Const NODBZ As Double = 0.000000001 ...

    X = Y / (Z + NODBZ)

    Then just round it when you are done.

    Riiiight. So, just divide by a very very small number, and your result turns out to be a very very large number, which might cause an overflow exception instead. Very useful.

    Or perhaps, you know, the divide-by-zero exception flags up the fact that there is a bug in the algorithm, and your little add-on just hid it?

    I know I'm replying to TopCod3r, but I have actually used this technique. If someone has a better solution, I'm listening.

    What's wrong with: If z = 0 Then ?

  • (cs) in reply to Teller

    Perhaps it didn't have an infinite number of $0 bills left, maybe someone had withdrawn one (or more) since it was refilled.

  • (cs) in reply to Stalker
    Stalker:
    JimM:
    Daedalus:
    How can you claim 4 is divisible by 0, if 4/0 is undefined?
    See how easy that was?
    Adjective divisible

    (arithmetic) Of an integer, that, when divided by another integer, leaves no remainder.

    Divisble (adj.): The susceptibility of being divided. (Yes, I can use google too!)

    Did I specify I was using the arithmetic definition of the word divisible?

    p.s. hint: We live under bridges...

  • (cs) in reply to More
    More:
    Zap Brannigan :
    I know I'm replying to TopCod3r, but I have actually used this technique. If someone has a better solution, I'm listening.
    What's wrong with: If z = 0 Then ?
    Too verbose (not to mention blatantly VB-centric!). If you must persist with VB then at least use IIf(Z=0, 0.000000000001, Z); personally I prefer (Z == 0? 0.00000000001: Z) - much more elegant and readable.
  • iToad (unregistered)

    For some banks, the ATM error message could be worse. It could simply say "Game Over".

  • (cs)

    If you accept the exception mission, does their bug tracking system assign the bug to you?

  • Gorfblot (unregistered) in reply to Monty
    Monty:
    Hey, this is Monty and while the ATM did present me an unsolvable problem it dispensed my 40 bucks with no trouble. :P

    So unfortunately it's not as simple as the machine running out of money. :P

    FWIW, on the ATMs I've worked on that number is stored in a XML file on the ATM itself, and can be either explicitly defined or set to lowest denomination of bills in stock.

    Lowest Denomination is picked up from another area of the file, which sets which cash cartridges are loaded and with what denomination of bills. If, say, Cash Cartridge 4 was not reloaded the last time the machine was serviced, and the denomination was set to 0 instead of empty... It would need to have bills in it though, otherwise it would read empty and be disabled.

    It's possible. I would hope the software would validate the bill denomination as being valid, but I certainly wouldn't bet on it. I've certainly not tried entering invalid bill denominations into ATMs, so can't be positive what happens.

  • More (unregistered) in reply to JimM
    JimM:
    More:
    Zap Brannigan :
    I know I'm replying to TopCod3r, but I have actually used this technique. If someone has a better solution, I'm listening.
    What's wrong with: If z = 0 Then ?
    Too verbose (not to mention blatantly VB-centric!). If you must persist with VB then at least use IIf(Z=0, 0.000000000001, Z); personally I prefer (Z == 0? 0.00000000001: Z) - much more elegant and readable.

    Nope. If I don't want to use 0.000000000001 if Z is 0. I want to do something else (preferably handle the problem). Otherwise I'm going to sit with stack overflow exceptions.

  • (cs) in reply to iToad
    iToad:
    For some banks, the ATM error message could be worse. It could simply say "Game Over".

    Even worse, there's a LOLCat saying "I'm Nside ur ATMz eating ur moniez!"

  • (cs) in reply to Old Coder
    Old Coder:
    Riiiight. So, just divide by a very very small number, and your result turns out to be a very very large number, which might cause an overflow exception instead. Very useful.

    Or perhaps, you know, the divide-by-zero exception flags up the fact that there is a bug in the algorithm, and your little add-on just hid it?

    Congrats! You may be Old Coder, but you're the first dummy in this thread to fall for the resident troll. What an honor!

    TopCod3r: Another great post. Thanks!

  • More (unregistered) in reply to More
    More:
    JimM:
    More:
    Zap Brannigan :
    I know I'm replying to TopCod3r, but I have actually used this technique. If someone has a better solution, I'm listening.
    What's wrong with: If z = 0 Then ?
    Too verbose (not to mention blatantly VB-centric!). If you must persist with VB then at least use IIf(Z=0, 0.000000000001, Z); personally I prefer (Z == 0? 0.00000000001: Z) - much more elegant and readable.

    Nope. If I don't want to use 0.000000000001 if Z is 0. I want to do something else (preferably handle the problem). Otherwise I'm going to sit with stack overflow exceptions.

    Actually, forget I said that (especially the "stack"... I was just busy working with a stack overflow problem :).

    Dividing by 0.000000000001 still gives me a "Divide by Zero" exception. So it's not a very good solution.

  • Foobar (unregistered) in reply to KenW
    KenW:
    Old Coder:
    Riiiight. So, just divide by a very very small number, and your result turns out to be a very very large number, which might cause an overflow exception instead. Very useful.

    Or perhaps, you know, the divide-by-zero exception flags up the fact that there is a bug in the algorithm, and your little add-on just hid it?

    Congrats! You may be Old Coder, but you're the first dummy in this thread to fall for the resident troll. What an honor!

    TopCod3r: Another great post. Thanks!

    Let's see how funny you are going to find it once someone picks up TopCod3r's code and causes the next Ariane rocket crash or something similar.

  • Justar (unregistered) in reply to LightStyx

    Can I have your stuff?

  • I walked the dinosaur (unregistered) in reply to TopCod3r
    TopCod3r:
    There is an EASY way to prevent divide by zero errors, so easy that I am surprised they haven't built it into the .NET framework yet... Simply add 0.000000001 to the denominator. This is such a small number that it makes no significant difference to the result. I like to make a constant, something like this and it works like a champ...

    Const NODBZ As Double = 0.000000001 ...

    X = Y / (Z + NODBZ)

    Then just round it when you are done.

    Overall this is a good solution, but I prefer to abstract all of this in a class (and require everyone to use it for ALL math operations). We are a Java shop and I am not allowed to give away our architecture for company policy reasons, but the basic idea is:

    public interface Operation { public Number do(Number n1, Number n2); };

    public class OperationFactory { public static Operation create(String type) { ... if (type.equals("divide") || type.equals("division")) { return new Division(); } } }

    public class Division implements Operation { public Number do(Number n1, Number n2) { try { Number result = n1.doubleValue() / n2.doubleValue(); return result; } catch (Exception e) { return new Double(0.0); } } }

    So in order to divide, it's really easy: Number result = OperationFactory.create("division").divide(5.0, 0.0); if (result.equals(new Double(0.0)) { ... HANDLE THE ERROR HERE }

    So you see if you forgot to check if the result is zero, your program won't crash (the result will just be zero!), which adds more robustness to the program. ALso note that if you are using Java 1.5 or above, you can take advantage of autoboxing and unboxing. However, our code needs to be compatible with Java 1.4, so we can't use this/

  • skoggkatt (unregistered) in reply to DaveyDaveDave
    DaveyDaveDave:
    Perhaps it didn't have an infinite number of $0 bills left, maybe someone had withdrawn one (or more) since it was refilled.

    infinite number minus one (or more) is still infinite number.

  • (cs) in reply to LightStyx
    LightStyx:
    rd:
    I'm not really sure, but I think it's EVE Online. Maybe someone else can verify.

    Congrats, you are the seventh person to point out this game. Yes, the screenshot is from EVE Online during a portion where a player is in a hangar, talking to an agent, and getting breifed on a mission. The game is riddled with Goons so don't bother playing unless you want to be raped by a bunch of drunken Irish, Scottish, and British men with nothing better to do but be ass pirates.

    Lets see, Peter Sellers was English, Spike Milligan was Irish and Harry Secombe was Welsh. So who is the Scottish goon that you're referring to?

  • (cs) in reply to skoggkatt
    skoggkatt:
    DaveyDaveDave:
    Perhaps it didn't have an infinite number of $0 bills left, maybe someone had withdrawn one (or more) since it was refilled.
    infinite number minus one (or more) is still infinite number.
    Infinty - 1 may still be infinite, but it is less than Infinity. Discuss ;^)
  • Ozz (unregistered) in reply to /b Zap Brannigan b/ (Deleted as Troll)
    /b Zap Brannigan b/ (Deleted as Troll):
    Yes that message would only make sense in the Eurpean version. The US message should be something like: You got no money fool! Would you like to apply for credit Y/N?
    No, the US message should be something like: You got no money fool! Would you like to apply for credit Y/Y?
  • (cs) in reply to Walleye
    Walleye:
    LightStyx:
    rd:
    I'm not really sure, but I think it's EVE Online. Maybe someone else can verify.

    Congrats, you are the seventh person to point out this game. Yes, the screenshot is from EVE Online during a portion where a player is in a hangar, talking to an agent, and getting breifed on a mission. The game is riddled with Goons so don't bother playing unless you want to be raped by a bunch of drunken Irish, Scottish, and British men with nothing better to do but be ass pirates.

    Lets see, Peter Sellers was English, Spike Milligan was Irish and Harry Secombe was Welsh. So who is the Scottish goon that you're referring to?

    Clearly, it's Sean Connery. You lose, Trebek! Ha ha ha ha ha!

  • Ozz (unregistered) in reply to operagost
    operagost:
    Walleye:
    LightStyx:
    Congrats, you are the seventh person to point out this game. Yes, the screenshot is from EVE Online during a portion where a player is in a hangar, talking to an agent, and getting breifed on a mission. The game is riddled with Goons so don't bother playing unless you want to be raped by a bunch of drunken Irish, Scottish, and British men with nothing better to do but be ass pirates.

    Lets see, Peter Sellers was English, Spike Milligan was Irish and Harry Secombe was Welsh. So who is the Scottish goon that you're referring to?

    Clearly, it's Sean Connery. You lose, Trebek! Ha ha ha ha ha!

    http://en.wikipedia.org/wiki/The_Goon_Show

  • RIP (unregistered)

    What, I thought that infinity was 16!

  • JD (unregistered) in reply to TopCod3r
    TopCod3r:
    There is an EASY way to prevent divide by zero errors, so easy that I am surprised they haven't built it into the .NET framework yet... Simply add 0.000000001 to the denominator. This is such a small number that it makes no significant difference to the result. I like to make a constant, something like this and it works like a champ...

    Const NODBZ As Double = 0.000000001 ...

    X = Y / (Z + NODBZ)

    Then just round it when you are done.

    Jesus man, even Error'd isn't safe from your highly proficient baiting. You must get up very early in the morning.

    By the way, that game is EVE Online, don't know if anyone's mentioned that yet...

  • EveOnline (unregistered)

    Hey does anyone know what game that screenshot is from?

  • math_guy (unregistered)

    Page Aleph-null out of Aleph-one

  • Math Whore (unregistered) in reply to JimM
    JimM:
    skoggkatt:
    DaveyDaveDave:
    Perhaps it didn't have an infinite number of $0 bills left, maybe someone had withdrawn one (or more) since it was refilled.
    infinite number minus one (or more) is still infinite number.
    Infinty - 1 may still be infinite, but it is less than Infinity. Discuss ;^)

    This is an easy one. Infinity is not a number - it's a concept. Infinity-1 is not a valid equation and therefore does not result in a valid number. It would be akin to saying that orange-1 is less than orange - it just doesn't make sense.

  • KäseMeister (unregistered) in reply to SS
    SS:
    I swear to God I'm going to pistol whip the next guy who says, "EVE Online."

    The real WTF is that this is apparently a reply to #220700:

    Teller:
    In which case the ATM's user interface could (and probably should) be simplified:

    "How many times your current balance would you like to withdraw? Please press 1, 2 or 3."

    Well done - you somehow manage to beat the bloke who thinks "a is divisible by b" means that a and b are both numbers. (Insert discussion about quaternions here.)

  • SQL2010 (unregistered) in reply to EveOnline
    EveOnline:
    Hey does anyone know what game that screenshot is from?

    It's the Enterprise Manager for the new MS-SQL beta.

  • Monkey Brains (unregistered) in reply to phrawzty
    phrawzty:
    What game is that a screenshot from ?

    I'm not sure if that's Eve Online or the Hello Kitty Island Adventure game, but I found this programmer's forum while doing a search on "Gardening" from Cuil. I have a newbie question. Does anyone know if the mv command is autonomic? Will it roll back if it runs out of space before completing the move?

    Thx

  • (cs) in reply to Jetts
    Jetts:
    Hey Farva, whats the name of that online game you like to play? You know the MMORPG with the space ships?

    Battletoads!

    (sorry, I couldn't resist)

  • Harrow (unregistered) in reply to TopCod3r
    TopCod3r:
    There is an EASY way to prevent divide by zero errors, so easy that I am surprised they haven't built it into the .NET framework yet... Simply add 0.000000001 to the denominator. This is such a small number that it makes no significant difference to the result. I like to make a constant, something like this and it works like a champ...

    Const NODBZ As Double = 0.000000001 ...

    X = Y / (Z + NODBZ)

    Then just round it when you are done.

    Now that you've become famous for this, what do you do if you ever want to post a comment that is not a troll?

    -Harrow?

  • Wizard Stan (unregistered) in reply to Ozz
    Ozz:
    /b Zap Brannigan b/ (Deleted as Troll):
    Yes that message would only make sense in the Eurpean version. The US message should be something like: You got no money fool! Would you like to apply for credit Y/N?
    No, the US message should be something like: You got no money fool! Would you like to apply for credit Y/Y?
    No, the US message would be "Here's your money" And then they would charge you $40 overdraft fee, plus an additional $40 overdraft fee because you didn't have the money to cover the first overdraft fee. The second overdraft fee is a freebee, so be grateful! They'll then charge you a $40 processing fee when you try to deposit money to bring your account back to positive, and then another pair of $40 overdraft fees because you didn't deposit enough to cover the processing fee you didn't know was going to be applied.

    captcha: EVE online

  • Omega Minus (unregistered) in reply to Math Whore
    Math Whore:

    This is an easy one. Infinity is not a number - it's a concept. Infinity-1 is not a valid equation and therefore does not result in a valid number. It would be akin to saying that orange-1 is less than orange - it just doesn't make sense.

    Orange - 1 is rag. Easy.

  • Robert') (unregistered) in reply to Monty
    Monty:
    Hey, this is Monty and while the ATM did present me an unsolvable problem it dispensed my 40 bucks with no trouble. :P

    So unfortunately it's not as simple as the machine running out of money. :P

    Did it dispense as an infinite number of $0 bills?

  • Mike D. (unregistered) in reply to Math Whore
    Math Whore:
    This is an easy one. Infinity is not a number - it's a concept. Infinity-1 is not a valid equation and therefore does not result in a valid number. It would be akin to saying that orange-1 is less than orange - it just doesn't make sense.
    The mathematically correct way of putting it is: "Infinity plus or minus any finite number is indistinguishable from infinity." I say "is indistinguishable from" instead of "is equal to" because the = operator (in math, not CS) isn't useful with infinity. You really need limits and other Calculus nastiness to play with infinities and not break something.

    Regarding how to check for a potential divide-by-zero without just catching the exception: The MATLAB folks here compare the absolute values of the denominators to a really small number, and if they find something below that, they do something about it. Having Infs and NaNs in your matrices can really slow things down with large data sets. MATLAB provides a function for finding these really small numbers: eps (short for epsilon):

    >> help eps
     EPS  Spacing of floating point numbers.
        D = EPS(X), is the positive distance from ABS(X) to the next larger in
        magnitude floating point number of the same precision as X.
        X may be either double precision or single precision.
        For all X, EPS(X) is equal to EPS(ABS(X)).
     
        EPS, with no arguments, is the distance from 1.0 to the next larger double
        precision number, that is EPS with no arguments returns 2^(-52).

    What you do about a potential divide-by-zero depends on the application. Sometimes you change the denominator to a minimum value; sometimes you make the denominator inf so the result is zero; sometimes you trim the data set to exclude the bad points; sometimes you throw an exception of your own.

    Nobody adds a small number before dividing because this just moves the domain of "values which will cause a divide-by-zero" over to one side; if you get a denominator which, when a small value is added, approaches zero, you're back where you started.

Leave a comment on “Unprepared For Divide_By_Zero”

Log In or post as a guest

Replying to comment #:

« Return to Article