- 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
Hey now, there are too girls in IT! Don't go getting all sexist on us now.
Admin
Just two eh? Who's the other one?
Admin
Admin
I've replaced a couple of in-house XML parsers with the Expat parser. As it's a SAX parser written in C which uses function pointers for callbacks, it has no effect whatsoever on data structures. If your in-house parser's logic wasn't push event driven, then it will have some effect on that.
Admin
I've even heard it said that "When dealing with floats, >= and <= are acceptable, but never use ==, !=, <, or >", and that guideline is complete nonsense (not to mention internally inconsistent). Even for checking exact equality of floats, there are some cases where you really do need to do that, cases where doing anything else would be incorrect.
If it's "always wrong" then why don't compilers show warnings about it (if not disallow it)? It necessarily must be determined on a case-by-case basis. Sure, it takes experience to be able to do so correctly, but a blanket rule is counterproductive here.
Admin
Eww.
Admin
Seriously dude! That's patently false to anyone with a speck of common sense. If >= works then, barring incompetence, so do the rest. We can only pray that whomever you heard that from has learned his lesson and stopped preaching heresies about data types he does not understand.
And floats/doubles are dangerous types to misunderstand.
Admin
are you certain you can't do it in C? (or at lest simpler than what you wrote)
math.h host's a plethora of functions, (what puzzels me is some of the really simple things that got left out...)
it's late and I'm very tierd so I have no clue what the point of the comparison is but here is a host of compares without exceptions, I'm pretty sure at least one of them could simplify what you wrote, and make it portable to non-intel machines since it's standard c99:
isgreater() determines (x) > (y) without an exception if x or y is NaN.
also since several of those probably are macros that expand to built in functions (or built int functions themselves) that use FUCOMI the compiler might just constant fold multiple invocations, and would be able to optimize around it better which inline asm will interfere with, so if at all possible avoid inline asm unless you're REALLY gonna optimize it, because otherwise the compiler WILL do a better job.
Admin
WRONG !0 generally results in 1
MAX_INT for an unsigned would be ~0 or ((unsigned)-1)
Admin
I could imagine that it was discovered that those floats could take NaN and INF values, and that this code submit fixes the compare function to support those.
NaN and INF aren't part of ISO C and can't be checked there. So you'd need inline assembly.
Of course the real fix would be to ensure that the flaots could never take those values, but that could require larger code changes...
But since there are no source code comments mentioned in the article, and no versioning submit text, it's just a guess.
Admin
Ah, sorry, comments like what I just wrote appeared on the last comment page :)
Admin
But I could be wrong.
CAPTCHA - saluto: those who are about to flame (me), I salute you.
Admin
Meanwhile, on planet earth, most of us are quite happy to call the little changes random.