DSPRelated.com
Forums

Rif: Re: Rif: RE: Mathematical function long x long / long

Started by Unknown November 12, 2002

In my example I explained only a part of formula. Maybe it's not clear. I
repeat the example:

D = A * B / C

If:
A = 214751
B = 10000
C = 30000
then
D must be 71583 !!

In your formula when perform "A * (B % C)" you overflow!! because (B % C)
= 30000 and
214751 * 30000 = 0x1800134d0 that exceed long size.
Is it right ?
HAve you other idea ?
Regards
Giuliano

"Jacob Christ"

< Per:

m> Cc:

Oggetto: Re: Rif: RE:
[motoroladsp] Mathematical function
11/11/02 19.32 long x long / long
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/
_____________________________________
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:

To Post:

To Leave:

Archives: http://www.yahoogroups.com/group/motoroladsp

More Groups: http://www.dsprelated.com/groups.php3 ">http://docs.yahoo.com/info/terms/




10000 % 30000 = 10000 not 30000
10000 / 30000 = 0

The MOD operator gives you the remainder of the integer (long)
division.

10000 * 214751 = 2147510000 = 0x800066F0
Which has overflowed as well

If the speed hit doesn't bother you try...

D = (long)((float)A * (float)B / (float)C);

I'm not sure yet how or even if the saturation and rounding bits
affect floats on the DSP compilers. But this works in Borland C++.

Jacob

--- In motoroladsp@y..., giuliano.to@q... wrote:
>
> In my example I explained only a part of formula. Maybe it's not
clear. I
> repeat the example:
>
> D = A * B / C
>
> If:
> A = 214751
> B = 10000
> C = 30000
> then
> D must be 71583 !!
>
> In your formula when perform "A * (B % C)" you overflow!! because
(B % C)
> = 30000 and
> 214751 * 30000 = 0x1800134d0 that exceed long size.
> Is it right ?
> HAve you other idea ?
> Regards
> Giuliano >

> "Jacob
Christ"

> <jacob@p... Per:
motoroladsp@y...
> m>
Cc:
> Oggetto: Re: Rif:
RE: [motoroladsp] Mathematical function
> 11/11/02 19.32 long x long /
long
>

>

>
> 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/ >
> _____________________________________
> 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/