- 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
Omg... still asking myself what kind of number is NOT > 1 AND is NOT = 1 AND is NOT < 1 AND is = -1...
Admin
Oh, boy. I do like the final option - the one where on the second unreachable case - he then doesn't divide by 100. Smooth.
Ah, unless VB understands the concept of NAN.
Admin
lmao.
You wonder why he didn't add an "if v_Value= 0..." just for good measure.
Admin
I'm glad this guy isn't on my team... I mean.. two unreachable cases, and 3 identical statements besides (4, but one is unreachable).. why not just:
ConvertPercent = v_value / 100
And be done with it?
Admin
Yikes. As often occurs, the post is a WTF but the comments are even worse so far.
All situations in this IF statement ARE reachable.
If v_value is >-1 and <1, then he leaves it alone. Otherwise, it is divided by 100. So he can't just divide it by 100 no matter way.
yes, the code is a WTF, much more convoluted than it needs to be. But these comments are pretty bad ... come on, guys, let's pay attention! I know it's the holidays and all, maybe you've had too much egg nog .....
Admin
(quick note: I forgot to add that I am making the assumption that there's a typo on the 3rd IF -- if not, then, yes, there are unreachable situations. But i suspect he meant to say < -1 and not < 1. I'm curious if the code was properly reproduced here on this web page)
Admin
What the F........?
I've seen some scary code but....this...is...
This person actually has a job!?
Admin
Please tell us all, what number is not greater than one, less than one, or one?
There must be some new additions to the number line...
Admin
I wonder how he would have coded the ConvertPolynomial function.
Admin
I call fake. Nobody is that dumb.
Oh wait, this is VB? Ah, ok nevermind, it is possible then
Admin
so it seems clear (?) to me that case three was supposed to be "ElseIf v_value < -1 Then"
That makes the function make some sense: A value between -1 and 1 is assumed to be already the decimal representation of the percentage and a value whose absolute value is 1 or greater is assumed to be the percentage representation of a percentage... ie .30 and 30 are both assumed to mean 30% or 0.3
Admin
So thats what it was probably supposed to be, but it's just buggy:
Admin
Admin
I agree with Jeff S that the guy meant to say < -1 for the third statement (although I don't agree with his characterization of the other commenters). Somebody probably made a typo along the way, but even if it was the coder, a typo is not a WTF.
What this guy wants to say is if abs(v_value) >= 1, divide by 100, otherwise don't. So the potential WTFs here are (a) not knowing about >=, (b) not taking absolute value, and (c) assuming that any number less than 1 is not a percent (ex. If I enter 0.5 meaning one half percent, his code will leave it as 0.5, turning it into 50%.).
Maybe he did (a) because he thought it was more readable. Maybe he chose (b) because he thought the abs() call would be too expensive. Maybe (c) isn't a problem because he doesn't have to deal with %s less than 1.
Admin
Yes, I am embarrased. [:$] I indicated that others should pay more attention, when I was not paying enough attention myself! I'm the one drinking too much eggnog, apparently ! [D]
Admin
Don't defend this!!! And all of you who write out what the code should be pat yourself on the back... you can code better then a monkey... (but barely)
The fact of the matter remains that the code posted SUCKS!!! even if it should be a -1... [8o|]
Admin
Hmm. Interesting and painful all at the same time. Supefluous is the perfect word for it (like Alex said).
Admin
So it's not possible to have 0.5% of something?!
It seems not. According to this guy, I meant 50%!
Yeah, sorry. My bad!
Admin
How about entering 0.005, then?
Admin
sqr(-1), eg imaginary numbers. That's what the else is for.
Admin
Boring
Not much of a WTF, fixed quickly, gone forever.
If v_value > 1
Or v_value = 1
Or v_value < 1
No beer for you! Go back to COBOL.
Static Function ConvertPercent(v_value As Double)
ConvertPercent = v_value / 100
End Function
<rant>
I would say that the real WTF is the ElseIf, a real piece of work ElseIf.
You want help debugging that, first get rid of all the ElseIf!
</rant>
Admin
...and your English skills are better than a monkey's.
Admin
All his code are belong to us.
Admin
I agree with this poster. Even if it's some convoluted typo, then it doesn't take away that this is a serious design mistake. Do _NOT_ mix datatypes. A computer hates ambiguity, and for good reason. Either enter 30% or 0.3 but not both.
Or you end up with terrible logic error like the quoted poster shows.
Admin
The webdesign of this page is becoming a wtf in itself. Why is the width fixed?
I hate scrolling horizontally. I liked the design much better when it was simple (say 2 months ago).
greetings
Admin
Assuming that you were using a language that supported NaN, wouldn't the result of NaN / 100 be NaN?
What I really like is the suggestion that to get support for 0.5% we should enter 0.005%. We'd need a smart wrapper program that would support it! How about ...
<FONT color=#0000ff>Static Function</FONT> AlwaysReallyConvertPercent(v_value <FONT color=blue>As Double</FONT>)
<FONT color=blue>If</FONT> (v_value > -1) and (v_value < 1) <FONT color=blue>Then</FONT>
AlwaysReallyConvertPercent = ConvertPercent(v_value / 100)
<FONT color=blue>Else</FONT>
AlwaysReallyConvertPercent = ConvertPercent(v_value)
<FONT color=blue>End If</FONT>
<FONT color=blue>End Function</FONT>
"That's real programming, that is!"
Admin
Width fixed? I haven't noticed =)
Then again, 1280x1024 on a 19 inch LCD does help....no horizontal scrolling here!
Admin
Well, yes.
But I was thinking about how to get to the second unreachable case. I'm going to assume a language implementation that (a) doesn't raise an exception when a NaN is compared to a value, and that (b) such a comparison always returns false except for the classic Nan != value version.
Admin
Time: 1995
and for an answer I got:Place: Boston, Mass
Data: simple 64-bit wide floats (totally normal: not NaN, or wierd, or anything. Just plain "double" variables like ".6")
Test Code:
Huh? Two numbers that aren't the same (!=) but where one isn't strictly greater than or less than the other? WTF?
Answer: Compiler bug on the DEC Alpha compiler! The numbers, while not "strange", were not "made" the same way. One was created on a VAX using the VAX "DFLOAT" bit fields and the other on an Alpha, also with DFLOAT bit fields. The Alpha is strictly IEEE floats only; DFLOAT are converted into IEEE floats, and that loses precision.
The > and < would convert the DFLOATs into IEEE format, dropping precision. With the slightly lower precision the numbers were the same. The == and !=, however, just do bit-by-bit compares at higher precision and the numbers are not the same.
Thank goodnessevery single double comparison was macro-ized and so the problem could be worked around with a simple cast-to-double (which made the compiler bug go away).
Peter Smith
Admin
In .NET you no longer have to set a return type? as in:
Admin
> And on another note, I think it's high time we had a logo. If you're the creative type, post your idea (rough draft ok).
I do agree but most here are developers. Creativity is something in the past for us... [<:o)] (Unless you see all the nice work on this site. You must be very creative to create those WTF's...)
Admin
NO! Nononononono! [:@]
I so hope you are joking! This is horrible, horrible code. Even if there's a typo, it's UGLY and fundamentally flawed in design!
Either go by percentage-values or don't! Don't mix and code!
Admin
WTF. If you use imaginary numbers, you can't use < or > anymore. They are not sorted.
Admin
What he probably meant was this:
He just forgot one dash.
Now it almost makes sense. He didn't want to convert numbers that already were converted.
Still, couple unnecessary elseifs...
Admin
You should perhaps read some of the posts above.
Admin
Admin
Yep, quoting works.
Admin
Assuming the type used (Double) is a IEEE754 floating-point type, there are three cases, where given the value v,
v > 1 is false
v < 1 is false
v = 1 is false
When v is NAN (Not a Number as discussed), positive infinity or negative infinity.
Here is some fun in Java (where floating-point types are per the IEEE754 standard):
// What is the output? Calculators are permitted.
public class X
{
public static void main(String[] args)
{
System.out.println(641 * 6700417);
System.out.println(16777216*256);
System.out.println(-2147483648 * -1);
}
}
Admin
Assuming the type used (Double) is a IEEE754 floating-point type, there are three cases, where given the value v,
v > 1 is false
v < 1 is false
v = 1 is false
When v is NAN (Not a Number as discussed), positive infinity or negative infinity.
Here is some fun in Java (where floating-point types are per the IEEE754 standard):
// What is the output? Calculators are permitted.
public class X
{
public static void main(String[] args)
{
System.out.println(641 * 6700417);
System.out.println(16777216*256);
System.out.println(-2147483648 * -1);
}
}
Admin
if v_value * v_value >= 1 then
ConvertPercent = v_value / 100
else
ConvertPercent = v_value
end if
Might be quicker than using the abs() mentioned before.
Still, baaad code!
Admin
Trick question. None of the values are floating point, they are all ints, so the issue of how floating point is handled, and NaN, is irrelevent. And all three expressions will overflow (not that the second or third will be reached) and 641*6700417 will cause a *looks it up* ArithmeticException to be thrown, which is not being caught by anything. So the output will be an unhandled exception message, and a backtrace. What do I win?
Admin
GEEZ! i cant believe i found this! get back to ur C! die coding pathetic C "apps" too!
Admin
bingo : this calls for "unreachable Code Error" from the compiler - everything below < 1 is not needed and will never get executed