- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Admin
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)
Admin
TRWTF here: The original author is unknown (???). Either that or they're too embarrassed to reveal their name.
Admin
Admin
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.
Admin
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.
Admin
That makes sense. Zero attempts results in zero failures, (and zero successes). Therefore, the test is 100% in compilance.
Admin
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.
Admin
Admin
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.
Admin
Admin
Admin
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.
Admin
It worked, the answer is: NaN
Oh what Fun!
Admin
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.
Admin
Heh...
works, too. (as in "It worked, the answer is: Infinity")
but
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
Admin
Appropriate when you really need to be sure you get the fly, er quotient.
Admin
I think Febtober would be 210th month
the 29th month should be Febtember, should it not?
Admin
just hope the value in the table is accurate. Of course they weren't populated by hand, right?
Admin
"It worked, the answer is: Infinity"
Infinity is 1.79769313486232E+308 * 2. You heard it here first.
Admin
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!
Admin
dinnerbone:
maybe there is a problem in .ToString?
Admin
Nope, put a breakpoint in there and you can see the value of result to be:
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:
Admin
I was sort of kidding, but yeah, I saw that behavior.
Very odd.
Admin
please send me teh tablez
Admin
Admin
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.
Admin
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
Admin
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.
Admin
<pedantic>
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.
Admin
It makes me wonder if there's something inherently wrong with HP's Quality Center when all bug reports are done in plaintext files.
Admin
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.
Admin
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? ;)
Admin
What's wrong with using an atomic bomb to swat a fly? Gets the job done, dain't it?
Admin
\0
Admin
Purple Monkey Dishwasher
Admin
Admin
Really takes the whole concept of a discrete ALU to all new heights.
Admin
I've never worked with cint.... worked with a few cunts, though.
Admin
How do you 'swat' a fly with an atomic bomb. I hear they're kind of heavy things?
Admin
Meanwhile, no success = 0% success. This presumably was the original point: 0/0 is indeterminate
Admin
Of course!!! There are 10 types of people in this world. Those who can understand binary, and those who can't.
Admin
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]
Admin
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>Admin
Believe it or not, the other day I came across dates in the YDM format. New one for me.
Admin
The worst part of all this is that VB.Net has an operator just for that: \
Admin
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 :)
Admin
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.
Admin
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.
Admin
When you hear a "whoosh" don't worry, that's just another thing that went over your head...