• Asztal (unregistered)

    See, befunge-93 does this right. Whenever a division by zero is encountered, the user is simply asked what they want the result to be.

  • Zygo (unregistered) in reply to AdT
    AdT:
    Zygo:
    If by "epsilon" you mean "one", or by "51" you mean zero, then yes.

    Ha ha! Another WTF comment par excellence. If divisor's absolute value is less than 10, then the addition will likely truncate a part of its mantissa (which happens to be 52 bits and not 51 bits wide for "double"s) in the addition. This is what the formula is intended to express. Your "corrections", OTOH, don't make any sense whatsoever.

    I lost you there. The original was:

    epsilon * 2 ^ (log2(10) - 51)

    which is roughly equivalent [1] to

    epsilon * epsilon * 10

    This could be fixed by replacing either epsilon with 1, or 51 with 0, which would give:

    epsilon * 2 ^ (log2(10) - 0) // replace 51 with 0

    or

    1 * 2 ^ (log2(10)-51) // replace epsilon with 1

    which are both equal to

    epsilon * 10

    [1] ignoring for the moment that epsilon is actually 2^-52, not 2^-51...only one correction per post ;-)

  • Fish Basket Gordo (unregistered) in reply to Just Some Guy
    Just Some Guy:
    New terms for standard mathematical words (eg "dividend" for "numerator"): check.

    Actually, dividend is the proper word for a number that is divided. Numerator would apply more to fractions (which are same, I realize), but using the word 'dividend' is about the only thing that is correct in this code. (Notice, the correct term for a number that divides another number is 'divisor', not 'divider'. That's where the non-standard terminology comes in.)

  • CoyneT (unregistered) in reply to SuperousOxide
    SuperousOxide:
    Wameng Vang:
    The junior developer is creating a framework for the something that the compiler/tool already handles by throwing exceptions, who knows he/she may create a try/catch framework to cover more error handling. Somebody needs to re-take Programming 101.

    This isn't just a junior developer. If a junior developer tried to catch divide-by-zero himself, the worst he'd do is make things a little more complex by requiring a function call for division. This is an utterly incompetant junior developer. His function attempts to return an answer to the divide by zero when there is no correct answer, and in doing so breaks division for almost every other case.

    Oh, sure, but you could always get around that like this:

     try {
       result = a / b;
     } catch (Exception.DivisionByZero)
       result = DivisionWithZero(a,b);
     }
    
    

    As to why: ..........I got nothing.

    ;)

  • (cs) in reply to ParkinT
    ParkinT:
    //remembers to keep the sign digit right

    Why would you need to put the sign on the right? Shouldn't it always be on the left? </sarcasm>

    Considering the sign is the only thing it gets right, I guess it's worth going to at least a bit of trouble over :)

  • (cs)

    public Double ASimpleMindedAproachToDividing(Double Dividend, Double Divider) { /// this also keeps the signs correct. return ( Divider==0 ? Null : ( Dividend / Divider ) );

    /// And it actually returns the correct value. }

  • J. B. Rainsberger (unregistered) in reply to Sgt. Preston

    It's simple:

    addend + augend = sum

    subtrahend - subtractor = difference

    multiplicand * multiplier = product

    dividend / divisor = quotient

    ....and yes, that's from memory. It might be wrong, but I'm pretty sure it's right. :)

  • kobal (unregistered) in reply to Waffles
    Waffles:
    Demi:
    Although this seems C# code, I'd like to point out that Java can divide by zero without errors. System.out.println(5.0 / 0); will print "Infinity". System.out.println(0.0 / 0); will print "NaN".
    Yup, pretty much any language can do that. Including C# or C++ for that matter. It's a property of the IEEE floating point standard. Few languages bother to actually throw exceptions on a divide-by-zero.

    But of course, that doesn't really make the result "correct". It's hard to do much useful with a NaN. :)

    You never dated the NaN I did, or you wouldn't talk like that - and I think you hit your caps lock key by mistake...

  • s. (unregistered)

    One Big Regret.

    He did it in a separate function. He didn't overload the division operator. Now that would have been beautiful.

  • (cs) in reply to chrismcb
    chrismcb:
    SuperousOxide:
    Beau "Porpus" Wilkinson:
        /// <summary>
        ///  shifts all windows
        /// </summary>
        /// <param name="processName">name of process</param>
    

    Truly, XML at its finest.

    If someone is going to fill out the comment like you show above, they wouldn't have added a better comment without the markup either.

    // Summary: // shifts all windows // // Params: // processName: Name of Process that owns the windows //

    WOW a much better comment because it is easier to humanly read.

    Humans don't need to read this. My IntelliSense needs to read it. And it can't read your comments, but it can read the original documentation.

    Note the subtle difference...

  • Sgt. Preston (unregistered) in reply to J. B. Rainsberger
    J. B. Rainsberger:
    It's simple:

    addend + augend = sum

    subtrahend - subtractor = difference

    multiplicand * multiplier = product

    dividend / divisor = quotient

    ....and yes, that's from memory. It might be wrong, but I'm pretty sure it's right. :)

    Good memory, Rainsberger! Personally, I don't recall ever seeing the word "augend". I believe we just called both terms of an addition operation "addends", but I'll take your word. When I learned this stuff, the Beatles were still together.

  • MikeB (unregistered) in reply to Hognoxious
    Hognoxious:
    Just Some Guy:
    New terms for standard mathematical words (eg "dividend" for "numerator"): check.
    - anyway, the one on the bottom) is always a power of ten, so I assume he did it like that because he never really mastered how to use decimals and/or percentages.

    Could be he used those powers of ten to avoid problems with the fact that some simple decimal fractions (like 0.1) are infinitely repeating binary floating point values. Decimal 0.1 is binary 0.00011001100110011........

  • me (unregistered) in reply to akatherder

    I don't know about C#, but in Java your code would not compile, since Random is a random number generator, not a number.

  • me (unregistered) in reply to kobal

    Java will only divide by zero safely if one of the values is a double (it doesn't matter which), when it automatically casts the other to a double as well. If you try to use integer division by zero, Java throws a java.lang.ArithmeticException

  • jercos (unregistered) in reply to Asztal
    Asztal:
    See, befunge-93 does this right. Whenever a division by zero is encountered, the user is simply asked what they want the result to be.
    Amen! along with modulo zero... best way to get a value from the user more than a single char at a time :D
  • Yousseb (unregistered) in reply to snoofle
    snoofle:
    HappilyEverAfter:
    ...You really should have seen how he managed to convert integer to decimal :D
    Please, do post !!!

    What??? Did you see the code? Please, don't!!!

  • JB (unregistered) in reply to Demi

    AS you've demonstrated, this only works with floats, as ints will still throw.

  • JB (unregistered) in reply to Sgt. Preston
    Sgt. Preston:
    J. B. Rainsberger:
    It's simple:

    addend + augend = sum

    subtrahend - subtractor = difference

    multiplicand * multiplier = product

    dividend / divisor = quotient

    ....and yes, that's from memory. It might be wrong, but I'm pretty sure it's right. :)

    Good memory, Rainsberger! Personally, I don't recall ever seeing the word "augend". I believe we just called both terms of an addition operation "addends", but I'll take your word. When I learned this stuff, the Beatles were still together.

    While "augend" is perfectly acceptable, it was coined during the Renaissance period and is rarely used in modern times. "Addend" (short for "Addendum", which is also perfectly valid) is the most commonly used term now.

  • bull (unregistered)

    I just read the article in the link, quite interesting.

    Such situation that enables division by zero should never happen. Even if a new number( 'nullity') is introduced, it just keep the program running in a crazy way, so even if the autopilot does not stop, your plane will crash into a mountain. Even if the pace maker still runs, your heart will beat with the frequency of Micro-processor ROFL

  • Josh Schneider (unregistered)

    Iz in yur functionz returnin incorrect doublzzzz.

  • B (unregistered)

    0/0.. OH SHI-

  • Judo Coder (unregistered) in reply to JB
    JB:
    Sgt. Preston:
    J. B. Rainsberger:
    It's simple:

    addend + augend = sum

    subtrahend - subtractor = difference

    multiplicand * multiplier = product

    dividend / divisor = quotient

    ....and yes, that's from memory. It might be wrong, but I'm pretty sure it's right. :)

    Good memory, Rainsberger! Personally, I don't recall ever seeing the word "augend". I believe we just called both terms of an addition operation "addends", but I'll take your word. When I learned this stuff, the Beatles were still together.

    While "augend" is perfectly acceptable, it was coined during the Renaissance period and is rarely used in modern times. "Addend" (short for "Addendum", which is also perfectly valid) is the most commonly used term now.

    Actually, "augend" wasn't coined during the Renaissance - it fell out of favour during the Renaissance. And the first two equations are incorrect. The list should be:

    augend + addend= sum minuend - subtrahend = difference multiplicand * multiplier = product dividend / divisor = quotient

    My first post here, and all I can say about what I just wrote is WTF?!

  • MathGeek2013 (unregistered)

    Dr. Anderson isn't the only one who did work on this subject. There's a Robert Miller in the United States who wrote a paper using similar arguments about what Anderson calls Nulity. Really cool read! He conects it to extra dimension and time. http://www.vixra.org/abs/1302.0036

Leave a comment on “Division By Zero, Solved Yet Again”

Log In or post as a guest

Replying to comment #:

« Return to Article