Subj : Re: Math error ??? doen't make sense! To : borland.public.cpp.borlandcpp From : waking Date : Fri Jul 02 2004 08:50 am On Thu, 1 Jul 2004 21:53:22 -0400, "Stan DeGroff" wrote: >int x,y; >long int z; >x=7000; >y=12000; >z=x*y; Since both x and y are ints (16 bits), the temporary variable used for the result of the multiplication before the allocation to z occurs is also an int. A 16-bit int is not large enough to hold the product, and hence truncation occurs. This can be avoided by promoting at least one of the variables to a long via a typecast. e.g. - z=(long)x*y; or z=x*(long)y; Then a long will be used for the temporary intermediate variable. For 32-bit targets an int is already 32-bits, the same size as a long, and therefore the cast is not needed. -- Wayne A. King (waking@idirect.com, Wayne_A_King@compuserve.com) .