It's simple to show that D = A * B / C can overflow no matter how you calculate it if the conditions are right. --- A = 0x7FFF FFFF B = 0x7FFF FFFF C = 0x1 will never fit in a signed long D, does D have to be a signed long? Jacob --- In motoroladsp@y..., giuliano.to@q... wrote: > > It's simple to show that > > A * (B % C) can overflow! > > For example if : > A = 214751 > B = 10000 > C = 30000 > > 214751 * 30000 = 0x1800134d0 > > Is it right ? > > Regards, > Giuliano > "Harrold Spier" > <harrold.spier@al Per: <giuliano.to@q...>, > tium.nl> <motoroladsp@y...> > Cc: > 07/11/02 16.39 Oggetto: RE: [motoroladsp] Mathematical function long x > long / long > > > Try: > > D = A * (B / C) + /* Main part */ > (A * (B % C)) / C; /* Correction with remainder */ > > Harrold > -----Original Message----- > From: giuliano.to@q... [mailto:giuliano.to@q...] > Sent: Thursday, November 07, 2002 15:41 > To: motoroladsp@y... > Subject: [motoroladsp] Mathematical function long x long / long > Does anyone have implemented a mathematical function to perform D = A * > B / C where A,B,C,D are "signed long" ? Obviusly A * B resualt can > exceed long size value. Thanks, Giuliano > _____________________________________ > Note: If you do a simple "reply" with your email client, only the author > of this message will receive your answer. You need to do a "reply all" > if you want your answer to be distributed to the entire group. > > _____________________________________ > About this discussion group: > > To Join: motoroladsp-subscribe@y... > > To Post: motoroladsp@y... > > To Leave: motoroladsp-unsubscribe@y... > > Archives: http://www.yahoogroups.com/group/motoroladsp > > More Groups: http://www.dsprelated.com/groups.php3 > ">http://docs.yahoo.com/info/terms/ |