586 Subj : Re: Math error ??? doen't make sense! To : borland.public.cpp.borlandcpp From : waking Date : Sat Jul 03 2004 02:07 am 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