- 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
That code doesn't even do what it's supposed to, it just does
-count
. I suppose that's why it was discovered.Also, the if condition is pointless, since "-0" is valid.
Admin
Pop quiz: how do you ensure that a number is negative? You could do something like:
0
is negative these days? :wtf:</pendant>
Admin
It can be in IEEE754 :P
Admin
I told that to a mathematician once.
He was not amused.
Admin
Quick lesson for the ignorant: One's complement says that a negative number is the one's complement (bitwise inversion) of the equivalent positive number. (So, in C terms:
-x
and~x
have the same value under one's complement.) One practical consequence is that there are two values of zero. One has all bits 0 and is unremarkable. The other has all bits 1, and is consequently a bit weird, because it is negative. The other interesting consequence is that, contrary to our normal expectations, INT_MIN is simply -INT_MAX, and not -INT_MAX-1.Admin
A note for the unwary: the last time I used a machine which used one's complement arithmetic was over 25 years ago. It was a CDC Cyber. It was also weird for other reasons, like its 18-bit address space and 60-bit integers, and its use of 6-bit characters, in CDC's own character set, CDC Display Code, which I suppose you could call CDCDC. These characters were very weird, and of course not C compatible (C requires 8-bit characters, and anyway you wouldn't want a character set where
'\000' == ':'
is true...).Admin
I'm sorry, are you from the past?
Ah. Apparently. Carry on, then.
Admin
Admin
That's all nice and dandy, but... the code is actually C#... Which runs on
x86[_64]
. And ARM? Maybe? Honestly not so sure about that. I guess it does since there are ARM versions of Win8?I think the "embedded systems!" argument kinda fails in this context, don't you?
Admin
This whole article is full of :wtf:. Is there a good reason for not using the unary minus operator? It's a thing even in Javascript, and it tends to be implemented efficiently.
Admin
I don't efficiency is a issue. Since they're equivalent they'd be compiled to the same bytecode.
C♯ compiler does optimization, right?
Admin
C# runs on ARM; it's used for WinRT apps
Admin
I prefer the following:
Admin
Not enough obfuscation.
Proposed fix:
Admin
I particularly enjoy using that method when count is 1073741824 (0x40000000) or higher.
Admin
Admin
No, but the whole "ah yes, but on Obscuratron 785ZX..." argument reeks of that meme. If you're not aware of it it's documented... somehwere. Not looking it up myself. Discosearching is a barrier to trolling the forum.
Well, is there a good reason to consider it as such? In the context of the original article? In the context of mathematics in general?
Also, in which non-broken system would
-1 * 0
not produce0
? I don't even care if it's-0
, a non-broken system shouldn't either. Is it pointless? Yes, it kinda is. That was also kinda my point: I find thatif
confusing. I wonder why it's there and why are we even checking ifcount
is greater than0
if we're screwing with that notion in the very next line. Something in it that my brain just has a problem parsing. Maybe I'm weird. Probably am, actually.I prefer the
abs
option, much clearer to me. I don't remember not usingabs
in that kind of situation unless I used a language incapable of it. Yes, those do exist. Still.Admin
Directive 613. "Unary operators give lack of flexibility, more costly evolution and inhibits the maintainability of applications. As such please remove from all program code."
Directive 613B. "Use of
0-variable
as a substitute for unary negative gives lack of flexibility, more costly evolution and inhibits the maintainability of applications. As such please remove from all program code."Directive 613C. "Use of
variable*-1
as a subsitute for unary negative gives lack of flexibility, more costly evolution and inhibits the maintainability of applications. As such please remove from all program code."Directive 613D. "Use of
~var+1
gives lack of flexibility, more costly evolution and inhibits the maintainability of applications. As such please remove from all program code."Directive 614. "Guys, stop being negative."
Admin
Cast to
unsigned int
…Admin
This is highly optimized for the zero case, as well as having the benefit of not creating a negative zero.
Admin
And then there are the systems where bytes aren't 8 bits (or multiples of 8 bits) long.
Actual quote from a young developer (*) when I told them about this fact (as I recall I'd seen or heard of at least 6, 7, 12, and 36, and I wouldn't be surprised if there were more):
"No, bytes are always 8 bits long. That's why in french they are called octet's."
Yes, I am from the past, and whatever official language-committee that came up with that translation has just demonstrated what's wrong with official language-committees :^)
(* - smart developer; just no wise in the ways of the world yet, I'm sure he's doing well now)
Admin
This is basically what I came here to say.
Damn time zones and my need for sleep!
Admin
(1) That is, the amount of memory by which you advance by adding one to the software-view of an address.
Yes, of course, I'm from the past...
Admin
It ain't positive.
Admin
Admin
I didn't say it was.
I wasn't being literal. I tried to discosearch for the meme definition thread but failed miserably. If I find it I'll post a link.
Admin
http://what.thedailywtf.com/t/wiki-memes/917
Scroll down to "embedded systems"
Admin
What about embedding in a building, as in “it'll take demolishing a wall to get the silly thing out”?
Admin
Actually, i did that once: the DSP TMS32032 family had a single int size, 32 bit. All int types were 32 bit. So, a char is 32 bit, and as a consequence, sizeof(char) == sizeof(int) == sizeof(long) == 1. We ported a big bit of software in C, and after that we were really sure the code was portable :smile:
Maurizio
Admin
French is TRWTF: 'bytes' is a new word. The existing word 'octet' seems to have
the correcta similar meaning; please use that instead.I made up that example but I have heard such weirdness described to me by one of my French teachers, who was from France.
Admin
well... when talking about older computers that operated on bytes that weren't 8 bits (they did exist. 7 bits was the most common of the bunch) i've often seen bytes used to refer to the native byte size and octet reserved for exactly 8 bits.
of course we've left the days of the PDP(and friends) long behind us so that distinction is fading fast.
Admin
This is how to ensure a negative number:
Thanks for the attention. I hope better WTF authors will volunteer now.
Admin
As someone else already mentioned, there's a danger of overflow for the above. However, it can be easily rectified:
Much better.
Admin
But the fact that the code was :wtf:'y, slow and buggy was the great thing about it!
Admin
Can't see why; functions that have a different limiting value at zero depending on whether you approach from above or from below (
lim[x->0+]f(x) != lim[x->0-]f(x)
) are well known.Admin
Yes, but a
0
is neither positive nor negative itself.Tried telling them
1
is prime too? :trollface:Admin
For functions that are only defined at zero in a limiting sense, the distinction has to be made.
Admin
Sorry, I disagree. You can talk about 0 as approached from the negative numbers, or as approached from the positive numbers, but "negative zero" is just zero, mathematically; it's built into the definition. Even in non-standard analysis you'll talk about f(\epsilon) and f(-\epsilon); the 0^+ notation is only a shorthand for lim_{n\to\infty} x_n where x_n > 0 for all n and x_n \to 0 as n \to \infty.
Yup, clear as mud. Someone get LaTeX support in Discourse, eh?
Admin
BBDownHTMLTex? That will end well!
Alternatively, you can use HTML symbol entities like
∞
(∞) and<sup>
and<sub>
I guess.Fractions... yeah, I know of no good way to get those using the limited HTML / CSS set we have on Discourse.
Admin
Admin
Well, those, yeah. Didn't think of that tbh, but it still doesn't help you with anything using expressions. Even using your
<sup>
and<sub>
hack it's still gonna be pretty damn messy.Admin
Admin
https://chara.cs.illinois.edu/sites/cs225/files/wat-duck.jpg
Admin
So you're saying 754 should have three zeros: 0+, 0-, and true 0?
Admin
Now that is what I call a waste of both code and hardware :wtf:
Admin
Which is why IEEE754 has them: recognition that a floating point number can't be any more accurate than a certain epsilon of the "true" value.
Mathematically it's like anything else: it means what it is defined to mean - nothing less and nothing more.
Admin
Admin
Musta been some o' that Linux hardware.
Admin
God save the French when we have Quantum machines.
Admin
I propose they translate
qubit
toqbert
.Filed under: Asterisks optional