Technical discussions about Freescale (Motorola) DSPs (including the DSP56000, DSP56300, DSP56600, 56800 DSPs).
|
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 |
|
|
|
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 |
|
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 |
|
I am using a DSP56F807 part and I get the following resultS (Which is what I
would expect):
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-----
Hi, I try to use fixed point math
function for multiplying and dividing
Can someone help me make sens of this? Bruno void main (void)
Var4 = mult(Var1,Var2);
Var6 = __mult(Var1,Var2);
} default fixed
By hand : Var1 : 0.000244148076
Var1 * Var2 : 1.907465E-6
------------------------ Yahoo! Groups Sponsor
---------------------~-->
http://www.c1tracking.com/l.asp?cid=6351
_____________________________________
________________________________________________________________________
________________________________________________________________________ This email has been scanned for all viruses by the MessageLabs SkyScan service. For more information visit http://www.messagelabs.com ________________________________________________________________________ |
|
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/ |