Skip to Main Content Skip to Search
Product Documentation

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 properties associated with a and b are different. The output fi object c has no local fimath.

a and b can both be fi objects with the same dimensions unless one is a scalar. If either a or b is scalar, then c has the dimensions of the nonscalar object. a and b can also be doubles, singles, or integers.

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
            Signedness: Signed
            WordLength: 40
        FractionLength: 30

Algorithms

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

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

c =
    8.5397

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

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

but not identical. When you use mpy, the fimath properties of a and b are not modified, and the output fi object c has no local fimath. When you use the syntax c = a .* b, where a and b have their own fimath objects, the output fi object c gets assigned the same fimath object as inputs a and b. See fimath Rules for Fixed-Point Arithmetic in the Fixed-Point Toolbox User's Guide for more information.

See Also

add | divide | fi | fimath | mrdivide | numerictype | rdivide | sub | sum

  


Free Early Verification Kit

Learn how to apply early verification to your development process through these technical resources.

How much time do you spend on testing to ensure implementation meets system-level requirements?

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