Every heard of Unary Negative... guess not?
-
I never thought I'd see code that warranted a WTF?
But here it is... spotted in an Access VBA project while working today.
' 4... Convert to positive number
If x <> 0 Then
gGetRecoveryCashPayments = x - (x * 2)
End Ifx was known to be negative as it was the sum of a bunch of negative numbers. But the report should have displayed a positive to make more sense to humans.
Needless to say, the code is now:
gGetRecoveryCashPayments = -x
Typical of this project - when I finish reviewing & updating a module there is typically about 25% of the code left, more functionality and less bugs.
ps. laughed for about 15 minutes on this one!
pps. even worse, I had to test the logic... and it works!
-
I don't know what he was smoking but I'd like to know where I can get some.
Hey, shouldn't this be in the sidebar WTF forum?
-
I'd like to know what the <> 0 check is for. Optimization?
-
@mightydrew said:
No, you got it all wrong.Needless to say, the code is now:
gGetRecoveryCashPayments = -x
gGetRecoveryCashPayments -= 2 * x * -1 /2
EDIT: Shit, I can't read. fixed
-
Thread moved to side bar wtf.
-
Does VBA not have an absolute value function?
-
@Someone You Know said:
Does VBA not have an absolute value function?
-
The first thing I thought, when seeing this, was "why doesn't he simply used x*x to make it positive, or better sqrt(x*x)"
(that happens when you work to much which vector length definitions...)
-
@mightydrew said:
Heh. That line cracks me up! if x is positive, you'd be churning out negative numbers. Even if x is supposed to be positive, you can't code with that assumption. That kind of stuff is what usually leads to someone withdrawing -500 bucks... ;)If x <> 0 Then
-
After studying IEEE floatint point formats for a week I once implemented your "x = -x" code as something like "x ^= 1<<31".... and then I realised wtf I was doing...
-
@ActionMan said:
After studying IEEE floatint point formats for a week I once implemented your "x = -x" code as something like "x ^= 1<<31".... and then I realised wtf I was doing...
God forbid you decide x should be an integer or double instead of a float!