• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: signed int
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: signed int


  • Subject: Re: signed int
  • From: "Jerry W. Walker" <email@hidden>
  • Date: Wed, 21 Dec 2005 13:52:11 -0500

Hi, Xavier,

I presume you're using Java, since this is a WebObjects mailing list.

If "virtual stock calculation", "quantity available" and "quantity requested" are each represented by int variables and each of the latter two hold the values that you're indicating, then I have no doubt that your calculation is returning a negative result.

If it were doing otherwise, the higher probability would be that your computer were computing integer arithmetic wrongly. It's happened, (remember the Pentium snafu), but in my experience, it's only happened in such obvious ways with esoteric specialized computers, never mainstream commercial processors that are running Java today. If your processor (or even the Java's compiled code) were guilty, I would expect to see a flood of such messages on every Java mailing list, and so far, yours is the only one I've seen.

I would suggest inserting System.out.println() statements around the offending calculation. Print out the values of each of the operands immediately before the calculation, then print out the result immediately after the calculation. Presuming some reasonable variable names, do this:

System.out.println("quantityAvailable = " + new Integer (quantityAvailable));
System.out.println("quantityRequested = " + new Integer (quantityRequested));


   virtualStockCalculation = quantityAvailable - quantityRequested;

System.out.println("virtualStockCalculation = " + new Integer (virtualStockCalculation));


If the results of the above are yielding a non-negative result and the operands have the values you described, I would very much like to see the code. It would help to see the actual code rather than pseudocode in that case. If the statements that you're representing with the pseudocode here are scattered throughout a much larger section of code, it would still help to see the actual declarations for each of the variables, the actual calculation statement and the actual statements you use to transfer the result back into some variable being tested to indicate a non-negative value.


For problems like these, the Devil is in the details, so it helps to see the details.

Regards,
Jerry

On Dec 21, 2005, at 12:01 PM, Dev WO wrote:

Hi list,
I don't really know where to look for, but here's my issue:
I've got a calculation based on the number (int) of product in stock.
This calculation should lead to negative number sometimes, for example, if I have a product A which was sold 6 times, if the stock is 0, the calculation should give -6...but it gives 6?!


Here's a snippet:
--------
quantity available of product A: 0
quantity requested: 6
virtual stock calculation = "quantity available" - "quantity requested"
--------


This should give -6 but not.

I printed the step to the log to see if it was a number formatting issue in my wocomponent, but it also displays 6 instead of -6 in the log.

Any pointer?

Thanks

Xavier
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com


This email sent to email@hidden


--
__ Jerry W. Walker,
WebObjects Developer/Instructor for High Performance Industrial Strength Internet Enabled Systems


    email@hidden
    203 278-4085        office






--
__ Jerry W. Walker,
WebObjects Developer/Instructor for High Performance Industrial Strength Internet Enabled Systems


    email@hidden
    203 278-4085        office



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: signed int
      • From: Dev WO <email@hidden>
References: 
 >signed int (From: Dev WO <email@hidden>)

  • Prev by Date: signed int
  • Next by Date: Re: signed int
  • Previous by thread: signed int
  • Next by thread: Re: signed int
  • Index(es):
    • Date
    • Thread