Absolute value of fi
object
c = abs(a)
c = abs(a,T)
c = abs(a,F)
c = abs(a,T,F)
c = abs(a)
returns the absolute value of fi
object a
with
the same numerictype
object as a
.
Intermediate quantities are calculated using the fimath
associated
with a
. The output fi
object c
has
the same local fimath as a
.
c = abs(a,T)
returns a fi
object
with a value equal to the absolute value of a
and numerictype
object T
.
Intermediate quantities are calculated using the fimath
associated
with a
and the output fi
object c
has
the same local fimath as a
. See Data Type Propagation Rules.
c = abs(a,F)
returns a fi
object
with a value equal to the absolute value of a
and
the same numerictype
object as a
.
Intermediate quantities are calculated using the fimath
object F
.
The output fi
object c
has no
local fimath.
c = abs(a,T,F)
returns a fi
object
with a value equal to the absolute value of a
and
the numerictype
object T
. Intermediate
quantities are calculated using the fimath
object F
.
The output fi
object c
has no
local fimath. See Data Type Propagation Rules.
Note:
When the 
abs
only supports fi
objects
with [Slope Bias] scaling when the bias is zero and the fractional
slope is one. abs
does not support complex fi
objects
of data type Boolean
.
When the object a
is real and has a signed
data type, the absolute value of the most negative value is problematic
since it is not representable. In this case, the absolute value saturates
to the most positive value representable by the data type if the OverflowAction
property
is set to saturate
. If OverflowAction
is wrap
,
the absolute value of the most negative value has no effect.
For syntaxes for which you specify a numerictype
object T
,
the abs
function follows the data type propagation
rules listed in the following table. In general, these rules can be
summarized as "floatingpoint data types are propagated."
This allows you to write code that can be used with both fixedpoint
and floatingpoint inputs.
Data Type of Input fi Object a  Data Type of numerictype object T  Data Type of Output c 


 Data type of 









Any 


Any 


The following example shows the difference between the absolute
value results for the most negative value representable by a signed
data type when OverflowAction
is saturate
or wrap
.
P = fipref('NumericTypeDisplay','full',... 'FimathDisplay','full'); a = fi(128) a = 128 DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 8 abs(a) ans = 127.9961 DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 8 a.OverflowAction = 'Wrap' a = 128 DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 8 RoundingMethod: Nearest OverflowAction: Wrap ProductMode: FullPrecision SumMode: FullPrecision abs(a) ans = 128 DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 8 RoundingMethod: Nearest OverflowAction: Wrap ProductMode: FullPrecision SumMode: FullPrecision
The following example shows the difference between the absolute
value results for complex and real fi
inputs that
have the most negative value representable by a signed data type when OverflowAction
is wrap
.
re = fi(1,1,16,15) re = 1 DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 15 im = fi(0,1,16,15) im = 0 DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 15 a = complex(re,im) a = 1 DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 15 abs(a,re.numerictype,fimath('OverflowAction','Wrap')) ans = 1.0000 DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 15 abs(re,re.numerictype,fimath('OverflowAction','Wrap')) ans = 1 DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 15
The following example shows how to specify numerictype
and fimath
objects
as optional arguments to control the result of the abs
function
for real inputs. When you specify a fimath
object
as an argument, that fimath
object is used to compute
intermediate quantities, and the resulting fi
object
has no local fimath.
a = fi(1,1,6,5,'OverflowAction','Wrap') a = 1 DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 6 FractionLength: 5 RoundingMethod: Nearest OverflowAction: Wrap ProductMode: FullPrecision SumMode: FullPrecision abs(a) ans = 1 DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 6 FractionLength: 5 RoundingMethod: Nearest OverflowAction: Wrap ProductMode: FullPrecision SumMode: FullPrecision f = fimath('OverflowAction','Saturate') f = RoundingMethod: Nearest OverflowAction: Wrap ProductMode: FullPrecision SumMode: FullPrecision abs(a,f) ans = 0.9688 DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 6 FractionLength: 5 t = numerictype(a.numerictype, 'Signed', false) t = DataTypeMode: Fixedpoint: binary point scaling Signedness: Unsigned WordLength: 6 FractionLength: 5 abs(a,t,f) ans = 1 DataTypeMode: Fixedpoint: binary point scaling Signedness: Unsigned WordLength: 6 FractionLength: 5
The following example shows how to specify numerictype
and fimath
objects
as optional arguments to control the result of the abs
function
for complex inputs.
a = fi(1i,1,16,15,'OverflowAction','Wrap') a = 1.0000  1.0000i DataTypeMode: Fixedpoint: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 15 RoundingMethod: Nearest OverflowAction: Wrap ProductMode: FullPrecision SumMode: FullPrecision t = numerictype(a.numerictype,'Signed',false) t = DataTypeMode: Fixedpoint: binary point scaling Signedness: Unsigned WordLength: 16 FractionLength: 15 abs(a,t) ans = 1.4142 DataTypeMode: Fixedpoint: binary point scaling Signedness: Unsigned WordLength: 16 FractionLength: 15 RoundingMethod: Nearest OverflowAction: Wrap ProductMode: FullPrecision SumMode: FullPrecision f = fimath('OverflowAction','Saturate','SumMode',... 'KeepLSB','SumWordLength',a.WordLength,... 'ProductMode','specifyprecision',... 'ProductWordLength',a.WordLength,... 'ProductFractionLength',a.FractionLength) f = RoundingMethod: Nearest OverflowAction: Saturate ProductMode: SpecifyPrecision ProductWordLength: 16 ProductFractionLength: 15 SumMode: KeepLSB SumWordLength: 16 CastBeforeSum: true abs(a,t,f) ans = 1.4142 DataTypeMode: Fixedpoint: binary point scaling Signedness: Unsigned WordLength: 16 FractionLength: 15