Sign in

username:

password:



Not a member?

Search motoroladsp



Search tips

Subscribe to motoroladsp



motoroladsp by Keywords

56303 | 563xx | 5680 | 56805 | 5680x | 56F80 | 56F800DEMO | 56F805 | 56f807 | 56F830 | ADC | Bootloader | Codec | CodeWarrior | CW5 | CW6 | Debugger | DSP56303 | DSP56303EVM | DSP563xx | DSP5680 | DSP56800 | DSP56807 | DSP56858 | DSP56858EVM | DSP56F803 | DSP56F805 | DSP56F807 | DSP56F80x | DSP56F826 | DSP56F827 | DSP56F8xx | EVM | FFT | Flash_over_jtag | GPIO | Interrupt | Interrupts | JTAG | LCD | Linker | MCF5307 | Metrowerks | Modulus | MSCAN | PCMaster | PWM | Quad | Rif | RTOS | SDK | SPI

Ads

Discussion Groups

Discussion Groups | Freescale DSPs | Rif: Re: Rif: RE: Mathematical function long x long / long

Technical discussions about Freescale (Motorola) DSPs (including the DSP56000, DSP56300, DSP56600, 56800 DSPs).

  

Post a new Thread

Rif: Re: Rif: RE: Mathematical function long x long / long - Author Unknown - Nov 12 8:43:00 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 > _____________________________________
> /groups.php3
_____________________________________
/groups.php3





(You need to be a member of motoroladsp -- send a blank email to motoroladsp-subscribe@yahoogroups.com )

RE: Mathematical function long x long / long - Jacob Christ - Nov 12 16:52:00 2002


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
> >
> >
> >
> >
> >
> > _____________________________________
> > /groups.php3
> >
> >
> >
> _____________________________________
> /groups.php3




(You need to be a member of motoroladsp -- send a blank email to motoroladsp-subscribe@yahoogroups.com )