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

Discussion Groups

Discussion Groups | Freescale DSPs | Re: Re: Fixed point math!

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

  

Post a new Thread

Fixed point math! - Bruno Tremblay - Sep 22 17:48:00 2003



Hi,

I try to use fixed point math function for multiplying and dividing
numbers.
So I tried to verify by hand the results and they don't match.

Can someone help me make sens of this?

Bruno void main (void)
{
Frac16 Var1 = 0x0008;
Frac16 Var2 = 0x0100;
Frac16 Var3 = 0x0200;
Frac16 Var4;
Frac16 Var5;
Frac16 Var6;
Frac16 Var7;

Var4 = mult(Var1,Var2);
Var5 = div_s (Var2,Var3);

Var6 = __mult(Var1,Var2);
Var7 = __div(Var2,Var3); }

default fixed
Var1 : 8 0.0002441406
Var2 : 256 0.007812500
Var3 : 512 0.01562500
Var4 : 16384 0.5000000
Var5 : 740 0.02258301
Var6 : 272 0.008300781
Var7 : 671 0.02047729

By hand :

Var1 : 0.000244148076
Var2 : 0.00781273843
Var3 : 0.0156254769

Var1 * Var2 : 1.907465E-6
Var2 / Var3 : 0.49999999872






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

Re: Fixed point math! - isierra95 - Sep 22 21:16:00 2003

Bruno,
A floating point number is 32 bits, made up of 23 bits for the
mantissa, 8 bits for exp and 1 sign bit. It will also round up to
the nearest even value by default. Regards,
Irene
--- In , "Bruno Tremblay"
<btremblay@g...> wrote:
> Hi,
>
> I try to use fixed point math function for multiplying and
dividing
> numbers.
> So I tried to verify by hand the results and they don't match.
>
> Can someone help me make sens of this?
>
> Bruno > void main (void)
> {
> Frac16 Var1 = 0x0008;
> Frac16 Var2 = 0x0100;
> Frac16 Var3 = 0x0200;
> Frac16 Var4;
> Frac16 Var5;
> Frac16 Var6;
> Frac16 Var7;
>
> Var4 = mult(Var1,Var2);
> Var5 = div_s (Var2,Var3);
>
> Var6 = __mult(Var1,Var2);
> Var7 = __div(Var2,Var3); > }
>
> default fixed
> Var1 : 8 0.0002441406
> Var2 : 256 0.007812500
> Var3 : 512 0.01562500
> Var4 : 16384 0.5000000
> Var5 : 740 0.02258301
> Var6 : 272 0.008300781
> Var7 : 671 0.02047729
>
> By hand :
>
> Var1 : 0.000244148076
> Var2 : 0.00781273843
> Var3 : 0.0156254769
>
> Var1 * Var2 : 1.907465E-6
> Var2 / Var3 : 0.49999999872




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

Re: Fixed point math! - kirkm54 - Sep 22 21:34:00 2003

Bruno,

When I run this code I get:
Var1 = 8
Var2 = 256
Var3 = 512
Var4 = 0
Var5 = 16384
Var6 = 0
Var7 = 16384

I think these results make sense.

If you think of them as fractions:
Var1 * Var2 = (8/32768) * (256/32768) = 1.907348E-6
The result of mult is only 16 bits.
The smallest number that can be represented in a 16 bit fraction is
1/32768 = 3.051757E-5 so Var4 and Var6 get truncated to 0.

Var2 / Var3 = 256 / 512 = 0.5 = 16384 / 32768

Kirk
--- In , "Bruno Tremblay" <btremblay@g...>
wrote:
> Hi,
>
> I try to use fixed point math function for multiplying and
dividing
> numbers.
> So I tried to verify by hand the results and they don't match.
>
> Can someone help me make sens of this?
>
> Bruno > void main (void)
> {
> Frac16 Var1 = 0x0008;
> Frac16 Var2 = 0x0100;
> Frac16 Var3 = 0x0200;
> Frac16 Var4;
> Frac16 Var5;
> Frac16 Var6;
> Frac16 Var7;
>
> Var4 = mult(Var1,Var2);
> Var5 = div_s (Var2,Var3);
>
> Var6 = __mult(Var1,Var2);
> Var7 = __div(Var2,Var3); > }
>
> default fixed
> Var1 : 8 0.0002441406
> Var2 : 256 0.007812500
> Var3 : 512 0.01562500
> Var4 : 16384 0.5000000
> Var5 : 740 0.02258301
> Var6 : 272 0.008300781
> Var7 : 671 0.02047729
>
> By hand :
>
> Var1 : 0.000244148076
> Var2 : 0.00781273843
> Var3 : 0.0156254769
>
> Var1 * Var2 : 1.907465E-6
> Var2 / Var3 : 0.49999999872




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

RE: Fixed point math! - Johnson, Jerry - Sep 22 21:58:00 2003

RE: [motoroladsp] Fixed point math!

I am using a DSP56F807 part and I get the following resultS (Which is what I would expect):
Var4 :  0               (Frac16)0.0
Var5 :  16384           (Frac16)0.5
Var6 :  0               (Frac16)0.0
Var7 :  16384           (Frac16)0.5


The multiply of 8 times 256 is less than the resolution of a Frac16 number, and is too small to round up to 1/32768 (0.000030517578125)!

0.000244140625 * 0.0078125 = 0.0000019073486328125

Jerry.

-----Original Message-----
From: Bruno Tremblay [mailto:b...@gentec.ca]
Sent: Monday, September 22, 2003 12:48 PM
To: m...@yahoogroups.com
Subject: [motoroladsp] Fixed point math!


Hi,

        I try to use fixed point math function for multiplying and dividing
numbers.
So I tried to verify by hand the results and they don't match.

Can someone help me make sens of this?

Bruno


void main (void)
{
        Frac16  Var1 = 0x0008;
        Frac16  Var2 = 0x0100;
        Frac16  Var3 = 0x0200;
        Frac16  Var4;
        Frac16  Var5;
        Frac16  Var6;
        Frac16  Var7;

        Var4 = mult(Var1,Var2);
        Var5 = div_s (Var2,Var3);

        Var6 = __mult(Var1,Var2);
        Var7 = __div(Var2,Var3);

}

                default fixed
Var1 :  8               0.0002441406
Var2 :  256             0.007812500
Var3 :  512             0.01562500
Var4 :  16384           0.5000000
Var5 :  740             0.02258301
Var6 :  272             0.008300781
Var7 :  671             0.02047729

By hand :

Var1 :  0.000244148076
Var2 :  0.00781273843
Var3 :  0.0156254769

Var1 * Var2 :   1.907465E-6
Var2 / Var3 :   0.49999999872

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Remanufactured Ink Cartridges & Refill Kits at MyInks.com for: HP $8-20. Epson $3-9, Canon $5-15, Lexmark $4-17. Free s/h over $50 (US & Canada).

http://www.c1tracking.com/l.asp?cid=6351
http://us.click.yahoo.com/0zJuRD/6CvGAA/qnsNAA/PNArlB/TM
---------------------------------------------------------------------~->

_____________________________________
/groups.php3
 



________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information visit http://www.messagelabs.com
________________________________________________________________________


________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information visit http://www.messagelabs.com
________________________________________________________________________


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

Re: Re: Fixed point math! - Paul Maddox - Sep 23 8:21:00 2003

Bruno,

> > I try to use fixed point math function for multiplying and
> dividing
> > numbers.
> > So I tried to verify by hand the results and they don't match.
> >
> > Can someone help me make sens of this?

wohoo!
been there!

do a shift right after the multiply :-)
for a good explanation ;-
http://www.soundart-hot.com/cgi-bin/ikonboard.cgi?s=3f70071555fcffff;act=ST;
f=2;t=117;hl=lord+avon

look at my message on june the 17th (127 * 1 = 254) and the reply from
Vincente Solsona.

Paul
--------------------------------------------------------------
Modulus Synthesisers ;-
Http://www.Modulus.Synth.net/




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