• Bork (unregistered) in reply to Zapp Brannigan
    Zapp Brannigan:
    HeyYall:
    I *almost* took a job where only IT guy was leaving.

    In about 3 days he was trying to train me to do a quite lengthy process that was only documented in his head and on random documents. He was leaving the U.S. for the U.K. for his new job. No one else knew how to run the system.

    The job consisted of a Java with SAS and a webserver. The Java part was written by a 3rd company in FL and got slower and slower as more data was entered (via users by a MS access application and various spreadsheets). And there was no backup server. :)

    What happens when you have a lone IT guy is very similar to what happens to species development in isolated populations. i.e. you wind up with some weird mutations. No mayonnaise in Ireland (No man is an island)
    this. QFAwesome.
  • (cs) in reply to Are Three
    Are Three:
    Thanks, Dinnerbone ...

    What about on the first try

     result = x / y
    
     result = Math.Log(result)
    

    I am curious (I should just install vb.net here) that result can carry around Infinity as an answer.

    So what is the proper way to do this? CInt throws an exception, so I suppose that would be the right function to use (if you didn't want a complex answer).

    I agree that even though the results are correct, and this is just mental fun and games right now since the original code checked for a 0 in the denominator, that I would want some sort of exception, usually. Wouldn't you?

    I think cint() threw an exception because "Infinity" was too big to fit in a standard 32-bit signed integer. Odd that it can fit in a double... Is Infinity really as big as we thought? Find out tonight at 10!

    I agree in that it's really odd that it casually uses "Infinity" as a result for /0 and doesn't throw any exceptions at all. As justsomedude said earlier, this is just a problem waiting to happen. It seems you have to check result.IsInfinity() whenever you think you might have done a /0 calculation (Or, you know, add sanity checks to stop /0 altogether).

    (Also, done a few playing around, all calculations on "Infinity" result in either 0, Infinity or NaN. Still no exceptions being thrown here, not even for NaN)

  • Kris (unregistered)

    TRWTF here: The original author is unknown (???). Either that or they're too embarrassed to reveal their name.

  • Bork (unregistered) in reply to Dan
    Dan:
    my name is missing:
    Using SQL to divide two integers is like using an atomic bomb to swat a fly.

    Nah, there's too much difference in power there. A rubber mallet would be a better fit.

    Right, but you have to nip out to the hardware store to buy one first, rather than use the newspaper on the table in front of you.

  • Are Three (unregistered) in reply to Dinnerbone

    Using VB 2008 Express Edition everything I try with

    x / 0

    returns System.OverflowException.

    So it looks like it's just .NET ?

    I bet all the other Express Editions (and maybe even all the "real" 2008 Editions) use the same library and will all return the same System.OverflowException result.

  • (cs) in reply to Are Three
    Are Three:
    Using VB 2008 Express Edition everything I try with

    x / 0

    returns System.OverflowException.

    So it looks like it's just .NET ?

    I bet all the other Express Editions (and maybe even all the "real" 2008 Editions) use the same library and will all return the same System.OverflowException result.

    What data type were you storing it in, and were you doing any conversions (Or automatic conversions if you played with the settings)? My first two pieces of code were written at work on Visual Studio 2008 and my last ones at home on Visual Studio 2010.

  • Americium (unregistered) in reply to undrline
    undrline:
    D C Ross:
    Seems simple enough. The built-in division function returned all kind of crazy "NaN" stuff sometimes. Only IntDivide can be relied upon to tell you that any number divided by zero is zero.

    The 0/0 indeterminate is funny, because business specifications usually want it to resolve to something that's still a metric. In the case of percentages, I run into "if zero met the test out of zero cases possible, then we want that to read 100% compliance."

    That makes sense. Zero attempts results in zero failures, (and zero successes). Therefore, the test is 100% in compilance.

  • Are Three (unregistered) in reply to Dinnerbone
    Dinnerbone:
    Are Three:
    Using VB 2008 Express Edition everything I try with

    x / 0

    returns System.OverflowException.

    So it looks like it's just .NET ?

    I bet all the other Express Editions (and maybe even all the "real" 2008 Editions) use the same library and will all return the same System.OverflowException result.

    What data type were you storing it in, and were you doing any conversions (Or automatic conversions if you played with the settings)? My first two pieces of code were written at work on Visual Studio 2008 and my last ones at home on Visual Studio 2010.

    Please ignore my previous post. I just cut and pasted all four code snippets from above by Dinnerbone and got the same answers that he did. I don't know what I did differently the first time I tried it, as I thought I had cut and pasted it exactly. Sorry for the wrongness. Please berate me as required.

  • (cs) in reply to Bork
    Bork:
    Dan:
    my name is missing:
    Using SQL to divide two integers is like using an atomic bomb to swat a fly.
    Nah, there's too much difference in power there. A rubber mallet would be a better fit.
    Right, but you have to nip out to the hardware store to buy one first, rather than use the newspaper on the table in front of you.
    With either rubber hammer or newspaper you still have the problem of fly guts splattered all over whatever the fly was sitting on. Atomic bombs inherently deal with this issue as well.
  • Are Three (unregistered) in reply to Are Three
    Are Three:
    Dinnerbone:
    Are Three:
    Using VB 2008 Express Edition everything I try with

    x / 0

    returns System.OverflowException.

    So it looks like it's just .NET ?

    I bet all the other Express Editions (and maybe even all the "real" 2008 Editions) use the same library and will all return the same System.OverflowException result.

    What data type were you storing it in, and were you doing any conversions (Or automatic conversions if you played with the settings)? My first two pieces of code were written at work on Visual Studio 2008 and my last ones at home on Visual Studio 2010.

    Please ignore my previous post. I just cut and pasted all four code snippets from above by Dinnerbone and got the same answers that he did. I don't know what I did differently the first time I tried it, as I thought I had cut and pasted it exactly. Sorry for the wrongness. Please berate me as required.

    The difference was this: Dim result As Integer = 0

    where as to get the "Infinity" result one must have Dim result As Double = 0

    Sorry, just figured it out.

  • (cs) in reply to Dinnerbone
    Dinnerbone:
    ...written at work on Visual Studio 2008 and my last ones at home on Visual Studio 2010.
    Ironic aside: why is it that these companies, which have much more cash than us, always have us using much older versions of software and lamer hardware than we buy for ourselves at home? </rant>
  • (cs) in reply to RandomUser423651
    RandomUser423651:
    Of course, it is not entirely uncommon (at least in US English) for the comma to indicate that items have been transposed. Thus, "Doe, John Alva" would represent "John Alva Doe" and "Boring Book Title, The" would represent "The Boring Book Title". In this way, the date may have originally been formatted as "2009 June 10", but was reordered so as not to begin with digits.
    What is interesting about your examples is that they all make sense. Refering to someone by last name (except within a family) is usually a good way to go, with additional qualifier added on as an afterthought. "Boring Book Title" is more important than "The". While a full date was likely originally formated "2009 June 10", it makes sense to refer to dates this year as "June 10", and add extra information when relevent (in conversations at least... data backups, not so much).
  • (cs) in reply to Are Three
    Are Three:
    The difference was this: Dim result As Integer = 0

    where as to get the "Infinity" result one must have Dim result As Double = 0

    Sorry, just figured it out.

    Mhm, as I said, it seems you can't fit Infinity inside a 32 bit integer. It's just a little bit too big :(

    This means that for people with automatic type casting turned on, storing them inside an integer will give an unrelated exception (Overflow, not DivideByZero), but for people using singles/doubles (Financial programs, for example) they'll have a little suprise when they do next months invoicing.

  • Are Three (unregistered)
    Dim x As Integer = 123
    Dim y As Integer = 0
    Dim result As Double = 0
    
    Try
       result = x / y
       result = result / result
    
       Console.WriteLine("It worked, the answer is: " & result.ToString())
       Catch ex As Exception
       Console.WriteLine("Uhoh, a " & ex.GetType().ToString() & " was thrown!")
    End Try
    
    Console.ReadKey(True)
    

    It worked, the answer is: NaN

    Oh what Fun!

  • (cs) in reply to snoofle
    snoofle:
    Dinnerbone:
    ...written at work on Visual Studio 2008 and my last ones at home on Visual Studio 2010.
    Ironic aside: why is it that these companies, which have much more cash than us, always have us using much older versions of software and lamer hardware than we buy for ourselves at home? </rant>

    It took me a good part of a year to get them to upgrade from 2005 (Finally got it last month), I'm not complaining just yet.

  • Are Three (unregistered)

    Heh...

    Dim result As Single = 0

    works, too. (as in "It worked, the answer is: Infinity")

    but

    Dim result As Decimal = 0

    doesn't.

    So Infinity is somewhere larger than a Decimal (which is defined as) +/-79,228,162,514,264,337,593,543,950,335 for zero-scaled numbers, that is, numbers with no decimal places. For numbers with 28 decimal places, the range is +/-7.9228162514264337593543950335. The smallest possible non-zero number is 0.0000000000000000000000000001 (+/-1E-28).

    But will fit in a Single (which is defined as) -3.402823E+38 through -1.401298E-45 for negative values; 1.401298E-45 through 3.402823E+38 for positive values

  • annoyingcowherd (unregistered) in reply to my name is missing
    Using SQL to divide two integers is like using an atomic bomb to swat a fly.

    Appropriate when you really need to be sure you get the fly, er quotient.

  • Somebody's NaN (unregistered) in reply to Sean Connery
    Sean Connery:
    girly programmer:
    I notice this gem was born on 08/29/08.

    So is that YMD or DMY?

    and the 29th month is...?

    Febtober!

    I think Febtober would be 210th month

    the 29th month should be Febtember, should it not?

  • ohmy (unregistered) in reply to annoyingcowherd
    annoyingcowherd:
    Using SQL to divide two integers is like using an atomic bomb to swat a fly.

    Appropriate when you really need to be sure you get the fly, er quotient.

    just hope the value in the table is accurate. Of course they weren't populated by hand, right?

  • (cs) in reply to Are Three
    Are Three:
    Heh...
    Dim result As Single = 0
    works, too. (as in "It worked, the answer is: Infinity")

    but

    Dim result As Decimal = 0

    doesn't.

    So Infinity is somewhere larger than a Decimal (which is defined as) +/-79,228,162,514,264,337,593,543,950,335 for zero-scaled numbers, that is, numbers with no decimal places. For numbers with 28 decimal places, the range is +/-7.9228162514264337593543950335. The smallest possible non-zero number is 0.0000000000000000000000000001 (+/-1E-28).

    But will fit in a Single (which is defined as) -3.402823E+38 through -1.401298E-45 for negative values; 1.401298E-45 through 3.402823E+38 for positive values

    Dim result As Double = 0
    
    Try
        result = Double.MaxValue * 2
        Console.WriteLine("It worked, the answer is: " & result.ToString())
    Catch ex As Exception
        Console.WriteLine("Uhoh, a " & ex.GetType().ToString() & " was thrown!")
    End Try
    
    Console.ReadKey(True)
    

    "It worked, the answer is: Infinity"

    Infinity is 1.79769313486232E+308 * 2. You heard it here first.

  • (cs)

    Thanks for letting me fool around with this some today. I have enjoyed the coding comments and messing around with the code enough to join the forums.

    One day I hope to get one of the many, many WTFs I have encountered in my years of experience posted to the TDWTF site. Until then, happy coding!

  • (cs)

    dinnerbone:

    maybe there is a problem in .ToString?

  • (cs) in reply to AreThree

    Nope, put a breakpoint in there and you can see the value of result to be:

    1.#INF

    I think it just sets it to infinity whenever you make it overflow, positive infinity if you go too high or negative infinity if you go too low. Changing MaxValue to MinValue gives:

    -1.#INF
  • (cs)

    I was sort of kidding, but yeah, I saw that behavior.

    Very odd.

  • (cs)

    please send me teh tablez

  • (cs) in reply to snoofle
    snoofle:
    Dinnerbone:
    ...written at work on Visual Studio 2008 and my last ones at home on Visual Studio 2010.
    Ironic aside: why is it that these companies, which have much more cash than us, always have us using much older versions of software and lamer hardware than we buy for ourselves at home? </rant>
    Well, given that 2010 is still in beta, I'd say sticking with 2008 for the present is the way to go for a business.
  • Garth (unregistered)

    Folks, this is cloud computing for the next millenium. The day has arrived when divide operations will not be performed on a single machine. That is simply too inefficient, considering the massive resources available. Divide operations will instead be dynamically crowd-sourced through tubes to peers all over the world. In XML.

  • Long (unregistered) in reply to Dinnerbone

    To point out the obvious, the int/decimal/etc. types have a size and range (0 - MAX for unsigned, and MIN - MAX if signed) so they cannot store things that are beyond those range. In contrast, floating point types also have the concept of infinities and NaN: http://en.wikipedia.org/wiki/IEEE_floating-point_standard

    Dinnerbone:
    Are Three:
    Heh...
    Dim result As Single = 0
    works, too. (as in "It worked, the answer is: Infinity")

    but

    Dim result As Decimal = 0

    doesn't.

    So Infinity is somewhere larger than a Decimal (which is defined as) +/-79,228,162,514,264,337,593,543,950,335 for zero-scaled numbers, that is, numbers with no decimal places. For numbers with 28 decimal places, the range is +/-7.9228162514264337593543950335. The smallest possible non-zero number is 0.0000000000000000000000000001 (+/-1E-28).

    But will fit in a Single (which is defined as) -3.402823E+38 through -1.401298E-45 for negative values; 1.401298E-45 through 3.402823E+38 for positive values

    Dim result As Double = 0
    
    Try
        result = Double.MaxValue * 2
        Console.WriteLine("It worked, the answer is: " & result.ToString())
    Catch ex As Exception
        Console.WriteLine("Uhoh, a " & ex.GetType().ToString() & " was thrown!")
    End Try
    
    Console.ReadKey(True)
    

    "It worked, the answer is: Infinity"

    Infinity is 1.79769313486232E+308 * 2. You heard it here first.

  • (cs)

    Long is right, of course:

    "To point out the obvious, the int/decimal/etc. types have a size and range (0 - MAX for unsigned, and MIN - MAX if signed) so they cannot store things that are beyond those range. In contrast, floating point types also have the concept of infinities and NaN: http://en.wikipedia.org/wiki/IEEE_floating-point_standard "

    I got carried away in fooling around with different data types and results and forgot that by definition, that is the expected behavior.

    Another gotcha to look out for, of course, is not knowing what is the appropriate data type to use for this type of calculation. However, some of the results using the double data type were interesting, in the sense that it could correctly compute with the Infinity.

  • (cs) in reply to Long

    <pedantic>

    Long:
    To point out the obvious, blah blah pedantic-mistake (0 - MAX for unsigned, and MIN - MAX if signed) blah blah quote-wikipedia:
    http://en.wikipedia.org/wiki/Signed_number_representations and http://en.wikipedia.org/wiki/Integer_(computer_science) seem to both think you're wrong above, just a tad bit...

    EX: Note the use of MAX as a single constant doesn't apply to both sides... Signed: −32,768 to +32,767 Unsigned: 0 to +65,535 </pedantic> <sarcastic> Yeah, I really thought we all knew that there was a large difference between int and float (or whichever makes you happy). </sarcastic> However, I didn't realize IEEE explicitly spelled out a "infinity" value for floats as a minimum part of the spec. Cool. Glad to know someone is paying attention to this stuff in the spec.

  • Matt (unregistered) in reply to Claxon
    Claxon:
    Steve:
    Another case of "Man who owns only a hammer" syndrome? I know someone who uses Excel to write press releases.

    That doesn't supprise me. In the company where I work excel is used for everything from data storage to bug reports (even though we have proper database and bug reporting solutions in place - they just don't get used).

    It makes me wonder if there's something inherently wrong with HP's Quality Center when all bug reports are done in plaintext files.

  • xous (unregistered) in reply to Moredate Madness

    Huh?

    I'm fairly certain it would have to be YY/DD/MM or MM/DD/YY but in this case it isn't relevant as both would end up having the same value when processed.

    2008-08-29 (YYYY-MM-DD).

    I think it's safe to assume this wasn't written in 1908.

  • (cs)

    I am amazed that any code that deals with floating point numbers (such as a Single or Double data type) gets the right answer at all.

    I mean, they are stored as binary fractions, so comparisons and operations involving Mod can result in some unexpected results, unless you are very careful and build in some ways to handle the issues.

    They still teach binary in Computer Science courses, don't they? ;)

  • mine too (unregistered) in reply to my name is missing
    my name is missing:
    Using SQL to divide two integers is like using an atomic bomb to swat a fly.

    What's wrong with using an atomic bomb to swat a fly? Gets the job done, dain't it?

  • fred (unregistered) in reply to Moredate Madness
    Moredate Madness:
    ThomsonsPier:
    Moredate Madness:
    I notice this gem was born on 08/29/08.

    So is that YMD or DMY?

    The twenty-ninth month of 2008 is May 2010, whereas the twenty-ninth month of 2008 is May 2010. From this, the answer should be obvious.
    This code is from the future!!! Arrrgggghhhhhhhh!!!!

    (There be terminators about...)

    \0

  • Krabapple (unregistered) in reply to Zapp Brannigan
    Zapp Brannigan:
    HeyYall:
    I *almost* took a job where only IT guy was leaving.

    In about 3 days he was trying to train me to do a quite lengthy process that was only documented in his head and on random documents. He was leaving the U.S. for the U.K. for his new job. No one else knew how to run the system.

    The job consisted of a Java with SAS and a webserver. The Java part was written by a 3rd company in FL and got slower and slower as more data was entered (via users by a MS access application and various spreadsheets). And there was no backup server. :)

    What happens when you have a lone IT guy is very similar to what happens to species development in isolated populations. i.e. you wind up with some weird mutations. No mayonnaise in Ireland (No man is an island)

    Purple Monkey Dishwasher

  • Bob (unregistered) in reply to drachenstern
    drachenstern:
    However, I didn't realize IEEE explicitly spelled out a "infinity" value for floats as a minimum part of the spec. Cool. Glad to know someone is paying attention to this stuff in the spec.
    One of the 'E's in there stands for 'engineer'. And it's actually applicable - unlike the typical software engineer, who is more like the cowboy's halfwit cousin than a mere "cowboy developer".
  • (cs)

    Really takes the whole concept of a discrete ALU to all new heights.

  • Jim (unregistered) in reply to Dinnerbone
    Dinnerbone:
    Are Three:
    Thanks, Dinnerbone ...

    What about on the first try

     result = x / y
    
     result = Math.Log(result)
    

    I am curious (I should just install vb.net here) that result can carry around Infinity as an answer.

    So what is the proper way to do this? CInt throws an exception, so I suppose that would be the right function to use (if you didn't want a complex answer).

    I agree that even though the results are correct, and this is just mental fun and games right now since the original code checked for a 0 in the denominator, that I would want some sort of exception, usually. Wouldn't you?

    I think cint() threw an exception because "Infinity" was too big to fit in a standard 32-bit signed integer. Odd that it can fit in a double... Is Infinity really as big as we thought? Find out tonight at 10!

    I agree in that it's really odd that it casually uses "Infinity" as a result for /0 and doesn't throw any exceptions at all. As justsomedude said earlier, this is just a problem waiting to happen. It seems you have to check result.IsInfinity() whenever you think you might have done a /0 calculation (Or, you know, add sanity checks to stop /0 altogether).

    (Also, done a few playing around, all calculations on "Infinity" result in either 0, Infinity or NaN. Still no exceptions being thrown here, not even for NaN)

    I've never worked with cint.... worked with a few cunts, though.

  • Suede (unregistered) in reply to Bork
    Bork:
    Dan:
    my name is missing:
    Using SQL to divide two integers is like using an atomic bomb to swat a fly.

    Nah, there's too much difference in power there. A rubber mallet would be a better fit.

    Right, but you have to nip out to the hardware store to buy one first, rather than use the newspaper on the table in front of you.

    How do you 'swat' a fly with an atomic bomb. I hear they're kind of heavy things?

  • WOAWERUsdf (unregistered) in reply to Americium
    Americium:
    undrline:
    D C Ross:
    Seems simple enough. The built-in division function returned all kind of crazy "NaN" stuff sometimes. Only IntDivide can be relied upon to tell you that any number divided by zero is zero.

    The 0/0 indeterminate is funny, because business specifications usually want it to resolve to something that's still a metric. In the case of percentages, I run into "if zero met the test out of zero cases possible, then we want that to read 100% compliance."

    That makes sense. Zero attempts results in zero failures, (and zero successes). Therefore, the test is 100% in compilance.

    Meanwhile, no success = 0% success. This presumably was the original point: 0/0 is indeterminate

  • Professor (unregistered) in reply to AreThree
    AreThree:
    I am amazed that any code that deals with floating point numbers (such as a Single or Double data type) gets the right answer at all.

    I mean, they are stored as binary fractions, so comparisons and operations involving Mod can result in some unexpected results, unless you are very careful and build in some ways to handle the issues.

    They still teach binary in Computer Science courses, don't they? ;)

    Of course!!! There are 10 types of people in this world. Those who can understand binary, and those who can't.

  • Evil Code Monkey (unregistered) in reply to ChrisE
    ChrisE:
    Come on, we all know America is too retarded to come up with a date format that orders each component by significance. That would be, you know, sensible and everything.

    In normal conversational usage, it would seem to me that the month and day would be more important than the year. Do you tell someone that you're going to a concert on 2009 June 10 20:00? Or do you tell them your going to a concert on June 10 at 20:00? Or just a concert at 20:00? It would seem to me that the significance of a component is directly related to the scenario in which it is to be used.

    [Troll detection reinitialized...terminating response]

  • Jo (unregistered) in reply to Code Dependent
    Code Dependent:
    snoofle:
    Dinnerbone:
    ...written at work on Visual Studio 2008 and my last ones at home on Visual Studio 2010.
    Ironic aside: why is it that these companies, which have much more cash than us, always have us using much older versions of software and lamer hardware than we buy for ourselves at home? </rant>
    Well, given that 2010 is still in beta, I'd say sticking with 2008 for the present is the way to go for a business.

    Panic sets in (for management) when upgrades are mentioned. They seem to fear that changing anything will somehow upset the very fabric of the universe. On a slightly related note, I have noticed that the greatest panic (and usually resistance) to any change comes from those who least understand what the change actually is. With this in mind, it makes sense that management panics and vetoes any change. Why is it that over the last decade or so, it seems IT companies have stopped hiring technical experts to progress into management roles, and have instead started to hire people with 'Management Qualafication's' from some School, College or University? There seems to be some assumption (probably in all industries, but certainly in IT) that you don't need to be able to have even a basic understanding of what the people below you are actually doing. I have had very few managers who understood even an extremely high-level (like International Airspace) view of what system's I've worked on actually do. ie (In English) Managers seem to think they're there to manage people to do a job they don't even remotely understand. It seems equivalent to having a workshop manager who doesn't really understand that there might be a difference between how a scooter and a prime mover work....

    </rant>
  • Rob (unregistered) in reply to Moredate Madness

    Believe it or not, the other day I came across dates in the YDM format. New one for me.

  • Andrew (unregistered)

    The worst part of all this is that VB.Net has an operator just for that: \

  • Anonymator (unregistered) in reply to snoofle
    snoofle:
    Ironic aside: why is it that these companies, which have much more cash than us, always have us using much older versions of software and lamer hardware than we buy for ourselves at home? </rant>

    It depends on the company - if the company's core business is creating software, they're usually up to date with the latest software and open to upgrading hardware to run said software :)

  • oheso (unregistered) in reply to Steve
    Steve:
    Another case of "Man who owns only a hammer" syndrome? I know someone who uses Excel to write press releases.

    I have a friend in the career counseling business who knows about a million people who use Excel to write CVs.

    In an unrelated note, a number of the recently unemployed in this town have been found murdered in apparent ninja attacks.

  • Al (unregistered) in reply to Whoevar

    And most of the options are retarded.

    I started using yyyymmdd when it was pointed out to me that it sorted correctly as a string.

  • Stark (unregistered) in reply to amischiefr

    When you hear a "whoosh" don't worry, that's just another thing that went over your head...

Leave a comment on “The Int Divide”

Log In or post as a guest

Replying to comment #:

« Return to Article