Main Content

add

Add two fi objects using fimath object

Description

example

c = add(F,a,b) adds fi objects 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 of fi object c has no local fimath.

Examples

collapse all

In this example, c is the 32-bit sum of a and b with a fraction length of 16.

a = fi(pi);
b = fi(exp(1));
F = fimath('SumMode','SpecifyPrecision',...
  'SumWordLength',32,'SumFractionLength',16);
c = add(F,a,b)
c = 

    5.8599

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 32
        FractionLength: 16

Input Arguments

collapse all

fimath object to use for addition.

Operands, specified as scalars, vectors, matrices, or multidimensional arrays.

a and b must both be fi objects and 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.

Data Types: fi
Complex Number Support: Yes

Algorithms

c = add(F,a,b)
is similar to
a.fimath = F;
b.fimath = F;
c = a + b

but not identical. When you use add, 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.

Extended Capabilities

HDL Code Generation
Generate Verilog and VHDL code for FPGA and ASIC designs using HDL Coder™.

Version History

Introduced before R2006a