Answered Need Help to Understand the follow code

  • Saturday, April 14, 2012 3:06 PM
     
     

    in one of the old code in my compony I found the next line 

    Dim num AsSingle = CSng(-((num2 = Single.MinValue) > False))

    i want to know what it do (could not found any Equivalent int visual studio books if somebody guide me to place the concept define it wiil help.

    Kind Regards

    David

All Replies

  • Saturday, April 14, 2012 4:00 PM
     
     Answered

    It seems to do something like this.

    Working from the inside to outside:
       X: num2 = Single.MinValue - test which is either True or False,
       Y: X > False - test is the result of X positive, which will give True or False
       Z: make the result of Y negative, that does not mean turn it from True to False or vice versa
       Convert the result of Z to a Single.

    I suspect it is relying on False being 0, and True being something that is non-zero. I'd guess it means something like: If num2 <> MinValue then num=0 else num = -1 (or possibly num =1, depending how False is represented).


    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

  • Saturday, April 14, 2012 7:41 PM
     
     Answered Has Code

    That sure is one ugly line of code.

        Sub UglyCode(ByVal num2 As Single)
            Dim num As Single = CSng(-((num2 = Single.MinValue) > False))
        End Sub
    
        Sub UglierCode(ByVal num2 As Single)
            Dim X As Boolean = (num2 = Single.MaxValue)
            Dim Y As Boolean = (X > False)
            Dim Z As Boolean = -Y
            Dim num As Single = CSng(Z)
        End Sub

    Rudy   =8^D

    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/