8bb Subj : Re: Math error ??? doen't make sense! To : borland.public.cpp.borlandcpp From : Stan DeGroff Date : Sun Jul 04 2004 12:02 am I see now, The explanation in any of the books I have is poor at best. The description for instructions, operators, etc are glossed over without the detail we were accustom to in the "old days". They basically say this thing simply multiplies the values and return a product. No mension of intermediate registers being used or need to type cast. Not only that, the initial post was the example given in the Sams book I mentioned other than the unsigned integer format character in the print statement. This is the toughest part I find any more... Finding the information in plain concise detail without fluff. I thank you for this input "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) . 0