Re: signed int
Re: signed int
- Subject: Re: signed int
- From: Dev WO <email@hidden>
- Date: Wed, 21 Dec 2005 22:03:18 +0100
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:
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