Long Variables can be negative?


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Long Variables can be negative?

    First code will work, if you use PBPL, because result is stored into temporally long variable.
    That is same as this

    Temp VAR LONG
    BVal VAR BYTE
    BVal = 0
    Temp = BVal - 1
    If Temp < 0 THEN Negative

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Long Variables can be negative?

    That's what I thought, makes sense, thanks!
    I haven't yet used PBPL in any project. I tried on my servo project but the "cost" of compiling with PBPL was too high so I managed without it.

    /Henrik.

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default Re: Long Variables can be negative?

    Although answered by pedja089, yes Henrik. It will work in either your example if you compile with PBPL. But as you said, the cost is high. So if you only need a comparisson, you can find other ways to do it just fine.

    Ioannis

  4. #4
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Long Variables can be negative?

    I think this won't work...
    Code:
    BVal VAR BYTE
    BVal = 0
    BVal = BVal - 1
    If BVal < 0 THEN Negative
    Because BVal is byte, and byte is always unsigned. So it can't be lower than 0. Correct me if I'm wrong...

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default Re: Long Variables can be negative?

    It WILL work only if you use PBPL because the result is stored temporarily in a long variable. This variable is checked, so yes it will work fine.

    For more info check the new PBP manual that clarifies the case.

    Ioannis

  6. #6
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Long Variables can be negative?

    Isn't result stored in BVal in this example?
    BVal = BVal - 1
    Result in BVal is 255(Checked with debugger). And because BYTE is unsigned it can't be negative. Program won't jump to negative.
    Then tried: If BVal - 1< 0 THEN Negative
    Then is negative.
    I really can't see how value in this statement is stored at end in temp var BVal = BVal - 1.
    That code is same as:
    Temp=BVal - 1
    BVal =Temp
    So we loose sing when value is passed to BVal.
    I'm done my homework, now you do yours

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default Re: Long Variables can be negative?

    Page 84-85 of the manual.

    Ioannis

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts