Subj : Re: Math error ??? doen't make sense! To : borland.public.cpp.borlandcpp From : Stan DeGroff Date : Sun Jul 04 2004 12:12 am Sorry, This was not explained in the operator descriptions at all. The Sams book and several other I've been using (like most of 'em today) do not do a good job of explaining what they are teaching. The original code I presented (other than the unsigned integer format in the print statement) was as presented in the book. My experience in assembly and/or PLC programming would have taken two 16 bit integers and expected a 32 bit result without having to type cast. I would only need to provide a 32 bit location/register for the result. No mention of any intermediate storage considerations being required. Thanks for the help Wayne. Stan "Wayne A. King" wrote in message news:40e602cc.378378@newsgroups.borland.com... > On Fri, 2 Jul 2004 20:31:26 -0400, "Stan DeGroff" wrote: > > >There ain't no overflow. as shown in the z result above. > > As I already explained, the overflow and truncation occur as > the result of the product exceeding the capacity of a 16-bit int. > Since both x and y are 16-bit ints, the *intermediate* result will > be stored in a 16-bit int. The typecast I showed forces promotion > to 32-bit long for the calculation. The multiplication occurs *before* > the assignment to a 32-bit long, hence its size is not relevant to > the capacity used for the product. > > >Multiply in Borland product must have both inputs to a multiply > >and the output all the same size variables. > > It depends on the values being stored. Also, promoting one of > either the multiplier or multiplicand results in automatic promotion > of the other and of the intermediate temporary variable used for > the result. This is the way it is in the C and C++ languages. It is not > unique to Borland. See the C FAQ at > http://www.eskimo.com/~scs/C-faq/faq.html > especially 3.14: > > "Why doesn't the code > int a = 1000, b = 1000; > long int c = a * b; > work? " > > http://www.eskimo.com/~scs/C-faq/q3.14.html > > > -- > Wayne A. King > (waking@idirect.com, Wayne_A_King@compuserve.com) .