mpy - Multiply two objects using fimath object

Syntax

c = F.mpy(a,b)

Description

c = F.mpy(a,b) performs elementwise multiplication on a and b using fimath object F. This is helpful in cases when you want to override the fimath objects of a and b, or if the fimath objects of a and b are different.

a and b must have the same dimensions unless one is a scalar. If either a or b is scalar, then c has the dimensions of the nonscalar object.

If either a or b is a fi object, and the other is a MATLAB® built-in numeric type, then the built-in object is cast to the word length of the fi object, preserving best-precision fraction length.

Examples

In this example, c is the 40-bit product of a and b with fraction length 30.

a = fi(pi);
b = fi(exp(1));
F = fimath('ProductMode','SpecifyPrecision',...
		'ProductWordLength',40,'ProductFractionLength',30);
c = F.mpy(a, b) 

c =
 
    8.5397


          DataTypeMode: Fixed-point: binary point scaling
                Signed: true
            WordLength: 40
        FractionLength: 30

             RoundMode: nearest
          OverflowMode: saturate
           ProductMode: SpecifyPrecision
     ProductWordLength: 40
 ProductFractionLength: 30
               SumMode: FullPrecision
      MaxSumWordLength: 128
         CastBeforeSum: true

Algorithm

c = F.mpy(a,b) is equivalent to

a.fimath = F;
b.fimath = F;
c = a .* b;

except that the fimath properties of a and b are not modified when you use the functional form.

See Also

add, divide, fi, fimath, numerictype, sub, sum

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS