Main Content

accumpos

Add two fi objects or values

Description

example

c = accumpos(a,b) adds a and b using the data type of a. b is cast into the data type of a. If a is a fi object, the default 'Floor' rounding method and default 'Wrap' overflow action are used. The fimath properties of a and b are ignored.

example

c = accumpos(a,b,RoundingMethod) adds a and b using the rounding method specified by RoundingMethod.

example

c = accumpos(a,b,RoundingMethod,OverflowAction) adds a and b using the rounding method specified by RoundingMethod and the overflow action specified by OverflowAction.

Examples

collapse all

This example shows how to add two fi numbers using accumpos.

Add two fi numbers

Add a and b, where a and b are both fi numbers, using the default rounding method of 'Floor' and overflow action of 'Wrap'.

a = fi(pi,1,16,13);
b = fi(1.5,1,16,14);
add_default = accumpos(a,b)
add_default = 
   -3.3584

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

Add two fi numbers using specified rounding and overflow action

Add a and b, where a and b are both fi numbers, using specified rounding method of 'Nearest' and overflow action of 'Saturate'.

a = fi(pi,1,16,13);
b = fi(1.5,1,16,14);
add_custom = accumpos(a,b,'Nearest','Saturate')
add_custom = 
    3.9999

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

Input Arguments

collapse all

Number to add. The data type of a is used to compute the output data type.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | fi

Number to add.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | fi

Rounding method to use if a is a fi object.

Example: c = accumpos(a,b,'Ceiling')

Data Types: string

Overflow action to take if a is a fi object.

Example: c = accumpos(a,b,'Ceiling','Saturate')

Data Types: string

Output Arguments

collapse all

Result of adding input a and input b.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced in R2012a