• (disco)

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.

• (disco)

Pop quiz: how do you ensure that a number is negative? You could do something like:

if (count > 0) {
count = count * -1
}


0 is negative these days? :wtf:

</pendant>

• (disco) in reply to Onyx

It can be in IEEE754 :P

• (disco) in reply to RaceProUK

I told that to a mathematician once.

He was not amused.

• (disco) in reply to Onyx
Onyx:

Pop quiz: how do you ensure that a number is negative? You could do something like:

if (count &gt; 0) {
count = count * -1
}


0 is negative these days? :wtf:

</pendant>

One's complement, dude! TRWTF is forgetting that one's complement exists. So that makes you TRWTF .

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.

• (disco)

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...).

• (disco) in reply to Steve_The_Cynic
Steve_The_Cynic:
One's complement, dude! TRWTF is forgetting that one's complement exists. So that makes you TRWTF .

I'm sorry, are you from the past?

Steve_The_Cynic:
A note for the unwary: the last time I used a machine which used one's complement arithmetic was over 25 years ago.

Ah. Apparently. Carry on, then.

• (disco) in reply to Onyx
Onyx:
I'm sorry, are you from the past?
Steve_The_Cynic:
A note for the unwary: the last time I used a machine which used one's complement arithmetic was over 25 years ago.

Ah. Apparently. Carry on. then.

The WTF is more the assumption that everything works the same way than the specifics of one's complement. It's worth remembering things like: * Not all C/C++ environments have int and long being the same size. * Even worse, in some environments, int isn't 32 bits. * Worse still, in some environments, int is only 16 bits. * Or, also pretty bad, on some other architectures, short is longer than 16 bits because there's no hardware support for 16-bit integers. * In some cases, long double is not different from double. * There are environments where a pointer is not the same size as an int. * There are environments where pointers to functions aren't the same size as pointers to data. * Either of them could be the large one. * All the integer types, from char all the way up to long long, could in fact be, say, 137 bits, and the implementation would still be "conformant". Not useful, perhaps, but conformant. On such a system, sizeof(type) would be 1 for all integer types, and a great deal of very useful software would fail utterly to work.
• (disco) in reply to Steve_The_Cynic

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?

• (disco)

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.

• (disco) in reply to dkf
dkf:
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.

I don't efficiency is a issue. Since they're equivalent they'd be compiled to the same bytecode.

C♯ compiler does optimization, right?

• (disco) in reply to Onyx

C# runs on ARM; it's used for WinRT apps

• (disco)

I prefer the following:

int loop = count * 2;
for (int i = 0; i < loop; i++) count--;

• (disco)
if (count > 0 || count < 0)


Not enough obfuscation.

Proposed fix:

if (!(!(~count < -1) && (0 <= count)))

• (disco) in reply to Vault_Dweller
Vault_Dweller:
I prefer the following:
int loop = count * 2;
for (int i = 0; i &lt; loop; i++) count--;


I particularly enjoy using that method when count is 1073741824 (0x40000000) or higher.

• (disco) in reply to Onyx
Onyx:
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?

Did I say "embedded systems"? And I didn't say that it wasn't C#. This whole discussion started with a (...) comment about 0 being negative, and kinda went from there...
• (disco) in reply to Steve_The_Cynic
Steve_The_Cynic:
Did I say "embedded systems"?

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.

Steve_The_Cynic:
This whole discussion started with a (...) comment about 0 being negative, and kinda went from there...

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 produce 0? 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 that if confusing. I wonder why it's there and why are we even checking if count is greater than 0 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 using abs in that kind of situation unless I used a language incapable of it. Yes, those do exist. Still.

• (disco) in reply to Onyx

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."

• (disco) in reply to CoyneTheDup
CoyneTheDup:
Directive 614. "Guys, stop being negative."

Cast to unsigned int

• (disco) in reply to Vault_Dweller

This is highly optimized for the zero case, as well as having the benefit of not creating a negative zero.

• (disco) in reply to Steve_The_Cynic

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)

• (disco) in reply to Zacrath
Zacrath:
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.

This is basically what I came here to say.

Damn time zones and my need for sleep!

• (disco) in reply to CodeSlave
CodeSlave:
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)

Re: octets: More to the point, ITU (ex CCITT) standards, among others, use the word "octet" in the English version of the text, in order to avoid the ambiguity of what "byte" means. And I've used machines where the single-unit-of-addressible-memory(1) was 60 bits (CDC Cyber mainframes), 16 bits (Norsk Data Nord-100 minicomputers) or even 8 bits (everything else I've worked with). A colleague many moons ago got the task of programming a machine with a four-bit memory width.

(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...

• (disco) in reply to Onyx
Onyx:
0 is negative these days?

It ain't positive.

• (disco) in reply to Onyx
Onyx:
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.
Demoting the CDC Cyber machines to "embedded systems" seems a bit harsh, though. They were a series of mainframes developed during the 1970s - the one I used (at university) was an 815 if memory serves, and could operate in 60-bit mode or 64-bit mode (where 8-bit ASCII characters were the norm). But in any event, they were one's complement...
It ain't positive.

I didn't say it was.

Steve_The_Cynic:
Demoting the CDC Cyber machines to "embedded systems" seems a bit harsh, though.

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.

• (disco) in reply to Onyx

http://what.thedailywtf.com/t/wiki-memes/917

Scroll down to "embedded systems"

• (disco) in reply to Steve_The_Cynic
Steve_The_Cynic:
Demoting the CDC Cyber machines to "embedded systems" seems a bit harsh

What about embedding in a building, as in “it'll take demolishing a wall to get the silly thing out”?

• (disco) in reply to Steve_The_Cynic
Steve_The_Cynic:
* All the integer types, from char all the way up to long long, could in fact be, say, 137 bits, and the implementation would still be "conformant". Not useful, perhaps, but conformant. On such a system, sizeof(type) would be 1 for all integer types, and a great deal of very useful software would fail utterly to work.

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

• (disco) in reply to CodeSlave
CodeSlave:
"No, bytes are always 8 bits long. That's why in french they are called octet's."

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.

• (disco) in reply to PleegWat
PleegWat:
'bytes' is a new word. The existing word 'octet' seems to have the correcta similar meaning;

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.

• (disco)

This is how to ensure a negative number:

count = -1;


Thanks for the attention. I hope better WTF authors will volunteer now.

• (disco) in reply to lcrawford
int loop = count * 2;
for (int i = 0; i < loop; i++) count--;

As someone else already mentioned, there's a danger of overflow for the above. However, it can be easily rectified:

int loop = 0;
while (count > 0) { ++loop; --count; }
while (loop > 0) { --loop; --count; }

Much better.

• (disco) in reply to Kian
Kian:
int loop = count * 2;
for (int i = 0; i &lt; loop; i++) count--;


As someone else already mentioned, there's a danger of overflow for the above. However, it can be easily rectified:

int loop = 0;
while (count &gt; 0) { ++loop; --count; }
while (loop &gt; 0) { --loop; --count; }


Much better.

But the fact that the code was :wtf:'y, slow and buggy was the great thing about it!

• (disco) in reply to Onyx

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.

• (disco) in reply to Watson

Yes, but a 0 is neither positive nor negative itself.

Tried telling them 1 is prime too? :trollface:

• (disco) in reply to Onyx

For functions that are only defined at zero in a limiting sense, the distinction has to be made.

• (disco) in reply to Watson

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?

• (disco) in reply to Tom_Potts
Tom_Potts:
Someone get LaTeX support in Discourse, eh?

BBDownHTMLTex? That will end well!

Alternatively, you can use HTML symbol entities like &infin; (∞) 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.

• (disco) in reply to Onyx
Onyx:
Fractions
1/2 1/2
• (disco) in reply to RaceProUK

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.

• (disco) in reply to bitti
if (-1 == 3) {
"fizz";
} else if (5) {
"buzz";
} else {
count = count + 1;
}

• (disco) in reply to Buddy

https://chara.cs.illinois.edu/sites/cs225/files/wat-duck.jpg

• (disco) in reply to Tom_Potts

So you're saying 754 should have three zeros: 0+, 0-, and true 0?

• (disco) in reply to RaceProUK

Now that is what I call a waste of both code and hardware :wtf:

• (disco) in reply to Tom_Potts

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.

• (disco) in reply to Onyx
• (disco) in reply to nobulate
nobulate:
Now that is what I call a waste of both code and hardware :wtf:

Musta been some o' that Linux hardware.

• (disco) in reply to PleegWat
PleegWat:
French is TRWTF: 'bytes' is a new word

God save the French when we have Quantum machines.

I propose they translate qubit to qbert.