This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem With Subtraction

I am trying to do a straight forward subtraction and am getting the wrong result every time. The code is as simple as

if(SetPoint>PulseCountLast) { error = SetPoint-PulseCountLast; }

All three variables are defined as uint16.

As you can see I ensured that I dont get a negative error value. Although I did try using error as signed number but still the faced the same issue. In any case the issue is when debugging is that SetPoint has a value of 0x0064 and PulseCountLast has a value of 0x0000 so I would expect an error value of 0x0065, however, the code always results in an error value of 0x0001 no matter what value the operands have.

I am really confused at this point what it might be...I would appreciate some help.

Parents
  • I guess posting that one liner according to the instructions would have made a world of difference.

    A world? Not really, no. But since you didn't really give us other clues, you didn't leave people much of a choice but to make assumptions based on what you did do: you failed to follow some pretty simple instructions, and made a pretty blatant error in some trivial maths at the core of your problem statement.

    When I posted my question I was not asking for a lesson in subtraction. Jumping on a typo to be like "gotcha" isnt particularly what I was looking for

    Well, by asking a question you give up the privilege of not having to listen to answers you don't like.

    In any case I figured the issue out.

    So, since you've pretty much failed to impress us thus far, why don't you try to demonstrate how clever you are by explaining what the real issue actually was? It's kind of impolite to claim you have the solution and not tell anyone about it. Mathematicians have been mad as hell at that Fermat fellow for centuries because of a stunt like that.

Reply
  • I guess posting that one liner according to the instructions would have made a world of difference.

    A world? Not really, no. But since you didn't really give us other clues, you didn't leave people much of a choice but to make assumptions based on what you did do: you failed to follow some pretty simple instructions, and made a pretty blatant error in some trivial maths at the core of your problem statement.

    When I posted my question I was not asking for a lesson in subtraction. Jumping on a typo to be like "gotcha" isnt particularly what I was looking for

    Well, by asking a question you give up the privilege of not having to listen to answers you don't like.

    In any case I figured the issue out.

    So, since you've pretty much failed to impress us thus far, why don't you try to demonstrate how clever you are by explaining what the real issue actually was? It's kind of impolite to claim you have the solution and not tell anyone about it. Mathematicians have been mad as hell at that Fermat fellow for centuries because of a stunt like that.

Children