• (cs)

    Omg... still asking myself what kind of number is NOT > 1 AND is NOT = 1 AND is NOT < 1 AND is = -1...

  • (unregistered)

    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.

  • (cs) in reply to

    lmao.


    You wonder why he didn't add an "if  v_Value= 0..." just for good measure.

  • (unregistered)

    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?

  • (cs)

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

  • (cs) in reply to Jeff S

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

  • (cs)

    What the F........?

    I've seen some scary code but....this...is...

    This person actually has a job!?

  • (unregistered) in reply to Jeff S
    Jeff S:
    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.


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

  • (unregistered)

    I wonder how he would have coded the ConvertPolynomial function.

  • (unregistered)

    I call fake. Nobody is that dumb.

    Oh wait, this is VB? Ah, ok nevermind, it is possible then

     

  • (unregistered)

    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

     

  • (unregistered)

    So thats what it was probably supposed to be, but it's just buggy:

    <FONT color=blue>Static Function</FONT> ConvertPercent(v_value <FONT color=blue>As Double</FONT>)
      <FONT color=blue>If</FONT> (v_value >= 1) <FONT color=#0000ff>or</FONT> (v_value <= -1) <FONT color=blue>Then</FONT>
        ConvertPercent = v_value / 100
      <FONT color=blue>Else</FONT> 
        ConvertPercent = v_value
      <FONT color=blue>End If</FONT> 
    <FONT color=blue>End Function</FONT>
  • (cs)
    Oddly, I would think that if you're trying to interpret a number as a percentage, and the number being converted is < 1, then it *shouldn't* be divided by 100.  But that's not what happens here.
     
    David Walker
  • (unregistered)

    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.

  • (cs)

    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]

  • (unregistered)

    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|]

  • (cs)

    Hmm. Interesting and painful all at the same time. Supefluous is the perfect word for it (like Alex said).

  • (cs) in reply to Jacob K

    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!

  • (unregistered)

    How about entering 0.005, then?

  • (cs) in reply to Romeo-Gresta

    sqr(-1), eg imaginary numbers. That's what the else is for.

  • (cs)

    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>

     

     

  • (unregistered)
    :
    you can code better then a monkey... (but barely)


    ...and your English skills are better than a monkey's.
  • (cs)
    Alex Papadimoulis:
    Ben Murphy found a developer who liked to cover all of his bases

    All his code are belong to us.

  • (unregistered) in reply to DJDanny
    DJDanny:

    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!



    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.
  • (unregistered)

    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

  • (unregistered)

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

  • (cs) in reply to
    :

    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

    Width fixed? I haven't noticed =)

    Then again, 1280x1024 on a 19 inch LCD does help....no horizontal scrolling here!

  • (unregistered) in reply to
    :

    Assuming that you were using a language that supported NaN, wouldn't the result of NaN / 100 be NaN?

    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.

  • (unregistered)

    Time: 1995
    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:

    if (a>b) printf (">\n");
    if (a >=b) printf (">=\n");
    if (a==b) printf ("==\n")
    if (a!=b) printf ("!=\n");
    if (a<=b) printf ("<=\n");
    if (a<b) printf ("<");
    and for an answer I got:

    >=
    !=
    <=

    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

          
  • (unregistered) in reply to
    :

    So thats what it was probably supposed to be, but it's just buggy:

    <FONT color=blue>Static Function</FONT> ConvertPercent(v_value <FONT color=blue>As Double</FONT>)
      <FONT color=blue>If</FONT> (v_value >= 1) <FONT color=#0000ff>or</FONT> (v_value <= -1) <FONT color=blue>Then</FONT>
        ConvertPercent = v_value / 100
      <FONT color=blue>Else</FONT> 
        ConvertPercent = v_value
      <FONT color=blue>End If</FONT> 
    <FONT color=blue>End Function</FONT>

    In .NET you no longer have to set a return type? as in:

    [code language="vb"]
    

    Function ConvertPercent(ByVal v_value As Double) As Double

    [/code]
  • (cs)

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

  • (unregistered) in reply to
    :
    How about entering 0.005, then?


    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!
  • (cs) in reply to Miles Archer

    Miles Archer:
    sqr(-1), eg imaginary numbers. That's what the else is for.

    WTF. If you use imaginary numbers, you can't use < or > anymore. They are not sorted.

  • (unregistered)

    What he probably meant was this:

    <font color="blue">Static Function</font> ConvertPercent(v_value <font color="blue">As Double</font>)
    <font color="blue">If</font> v_value > 1 <font color="blue">Then</font> ConvertPercent = v_value / 100 <font color="blue">ElseIf</font> v_value = 1 <font color="blue">Then</font> ConvertPercent = v_value / 100 <font color="blue">ElseIf</font> v_value < -1 <font color="blue">Then</font> ConvertPercent = v_value / 100 <font color="blue">ElseIf</font> v_value = -1 <font color="blue">Then</font> ConvertPercent = v_value / 100 <font color="blue">Else</font>
    ConvertPercent = v_value
    <font color="blue">End If</font>
    <font color="blue">End Function</font>



    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...
  • (unregistered) in reply to

    You should perhaps read some of the posts above.

  • (cs) in reply to fcarlier
    fcarlier:

    [image] Miles Archer wrote:
    sqr(-1), eg imaginary numbers. That's what the else is for.

    WTF. If you use imaginary numbers, you can't use < or > anymore. They are not sorted.

  • (unregistered) in reply to Maurits
    Maurits:
    [image] fcarlier wrote:

    [image] Miles Archer wrote:
    sqr(-1), eg imaginary numbers. That's what the else is for.

    WTF. If you use imaginary numbers, you can't use < or > anymore. They are not sorted.

    Yep, quoting works.

  • (unregistered)

    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);
        }
    }

  • (unregistered)

    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);
        }
    }

  • (cs)

    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!

  • (unregistered) in reply to
    :

    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);
        }
    }



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

    I call fake. Nobody is that dumb.

    Oh wait, this is VB? Ah, ok nevermind, it is possible then

     

    GEEZ! i cant believe i found this! get back to ur C! die coding pathetic C "apps" too!

  • eagle275 (unregistered) in reply to Romeo-Gresta
    Romeo-Gresta:
    Omg... still asking myself what kind of number is NOT > 1 AND is NOT = 1 AND is NOT < 1 AND is = -1...

    bingo : this calls for "unreachable Code Error" from the compiler - everything below < 1 is not needed and will never get executed

Leave a comment on “Covering All Cases ... and then some”

Log In or post as a guest

Replying to comment #:

« Return to Article