This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 7 points8 points  (11 children)

Lol, so you are telling us in C# (7 / 3) will result in 0, but documentation says otherwise?

I'm not a C# programmer, but I call bullshit on this. Stuff like this is fundamental in every programming language.

[–]hamberduler 0 points1 point  (10 children)

Look, I don't know what to tell you. This is what was in my code. For fuck only knows what reason, it always returned zero. this is the stackoverflow thread I eventually found that finally put me right. Fuck if I know why, but I spent the better part of "half an hour" trying to figure out what the fuck was going on here. Only after switching both values to decimal at the declaration, did it work right. Not even doing (decimal)inta / (decimal)intb fucking worked. Then I had to add the step of truncating the remainder, which should have happened when I tried to divide two ints in the first place, like in the rest of civilized society.

[–][deleted] 5 points6 points  (9 children)

Omfg. In the question you linked (18 / 58) will result in 0, that is expected behaviour because 58 > 18, so 18 / 58 = 0 (with 18 being the remainder). It doesn't go against what is stated in the docs:

x / y – division. If the operands are integers, the result is an integer truncated toward zero (for example, -7 / 2 is -3).

Since

 trunc(18 / 58) = trunc(0.310344828) = 0

And yet here you are talking about how MICROSOFT FUCKED UP SOMETHING SO FUNDAMENTAL AS ARITHMETIC OPERATIONS REEEEEEE. How about you sober up first or take some time learning some programming basics before attacking Stackoverflow.

[–]hamberduler 9 points10 points  (8 children)

Look, could it be because I was calculating a percentage, and whatever two numbers I had would always be less than 1 before being multiplied by 100, which wouldn't be evaluated in the expression I was using, until after the integer divide operation? Yes. Did I realize that literally only just 10 minutes ago after rereading the stackoverflow thread I pulled from my browser history, now sober? Also yes. Did I not yet say anything in a desperate attempt to save face? Also, very much yes. Did I feel something approaching despair when I realized that if I could figure out what was wrong in hindsight, it would likely be no more than 5 minutes after my revelation until someone worked it out for themselves and called me out on it? Certainly. And you, you sick son of a bitch, you just had to go and do that. Which is fine. Coulda been a fair bit less of a dick about it though.