• 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: Thu, 22 Dec 2005 10:53:55 -0500

Hi, Xavier,

Sorry I didn't get back to you sooner, but rather invested the evening with my family at The Big Apple Circus in New York City. It was a wise investment! :-)

Lachlan Deck has provided your answer (in a separate post), I think, in his comments:

// I think you'll want to add the available count rather than subtract
// so that whether the availability is positive or negative
// it will provide the status with the correct number

If virtualStockStatus = 0, quantity = 5 and quantityAvailable = 3, the operation:


virtualStockStatus = virtualStockStatus - ((quantityAvailable) - (quantity));

would be equivalent to:

  virtualStockStatus = 0 - (3 - 5)

or

  virtualStockStatus = 0 - 3 + 5 = 2

The answer, 2, is mathematically correct based on the formula you provided, but not, I think, the answer you're looking for. Substituting Lachlan's formula would get you closer, but I still have problems.

I don't see your virtualStockStatus as a meaningful number, unless I'm badly misunderstanding the problem.

It seems that you're iterating through the items for a customer's order. For each item in the order, you're computing a virtualStockStatus by increasing the current value of the virtualStockStatus by the amount available for this particular item and reducing it by the amount the customer ordered for this particular item. If the customer only orders one item, that makes some sense, but if the customer orders multiple items, what does the availability of one item have to do with the availability of a second item reported in the same single integer value?

Also, if the customer happened to order two quantities of the same item in this order, the quantity available would seem to be added into the virtualStockStatus twice.

Hope this helps.

Regards,
Jerry


On Dec 21, 2005, at 4:03 PM, Dev WO wrote:

Hi Jerry,
I don't think it comes from a weird hardware as my application behave the same on 2 different machine (PowerBook and Xserve).
So might be something I've done wrong, and I really have no doubt about that;)
so here's the method I'm using, it's within a framework. I'm using this to display my client with a page of all the "out of stock" product, and so he should have a negative virtual stock for the items...
===========
public int virtualStockStatus() {
// to generate the list of order not canceled nor already validated for shipping
int virtualStockStatus = 0; // To initialize the virtual stock
NSMutableArray orderItemsList = new NSMutableArray (customerOrderItems());
EOQualifier qual = EOQualifier.qualifierWithQualifierFormat ("(customerOrder.orderCanceledOn = null) and (customerOrder.paymentValidatedOn <> null) and (quantity <> quantityAvailable) and (customerOrder.shippedOrDeliveredOn = null)", null);
NSArray orderItemsListToTakeIntoAccount = (NSArray) EOQualifier.filteredArrayWithQualifier(orderItemsList, qual);
int i = 0;
while (i < orderItemsListToTakeIntoAccount.count()) {
CustomerOrderItem aCustomerOrderItem = (CustomerOrderItem) orderItemsListToTakeIntoAccount.objectAtIndex(i);
System.out.println("\n============\nQuantity requested: " + aCustomerOrderItem.quantity());
System.out.println("\n============\nQuantity available: " + aCustomerOrderItem.quantityAvailable());
if (aCustomerOrderItem.quantityAvailable() == null) {
virtualStockStatus = virtualStockStatus - (aCustomerOrderItem.quantity().intValue());
}
else {
virtualStockStatus = virtualStockStatus - ((aCustomerOrderItem.quantityAvailable().intValue()) - (aCustomerOrderItem.quantity().intValue()));
}
i++;
System.out.println("\n============\nVirtual stock in loop: " + virtualStockStatus);
}
System.out.println("\n============\nVirtual stock: " + virtualStockStatus);
return virtualStockStatus;
}


===========

the operands have the correct value, but the total is not negative....maybe I'm missing something obvious I can't see because I red it too much;)

thanks for your help Jerry,

Xavier



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:
@gmail.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







--
__ 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: Lachlan Deck <email@hidden>
References: 
 >signed int (From: Dev WO <email@hidden>)
 >Re: signed int (From: "Jerry W. Walker" <email@hidden>)
 >Re: signed int (From: Dev WO <email@hidden>)

  • Prev by Date: Re: WOTimer and Servlet Deploy
  • Next by Date: Re: Cannot find service Error
  • Previous by thread: Re: signed int
  • Next by thread: Re: signed int
  • Index(es):
    • Date
    • Thread