ufi
Construct unsigned fixed-point numeric object
Syntax
a = ufi
a = ufi(v)
a = ufi(v,w)
a = ufi(v,w,f)
a = ufi(v,w,slope,bias)
a = ufi(v,w,slopeadjustmentfactor,fixedexponent,bias)
Description
You can use the ufi
constructor function
in the following ways:
a = ufi
is the default constructor and returns an unsignedfi
object with no value, 16-bit word length, and 15-bit fraction length.a = ufi(v)
returns an unsigned fixed-point object with valuev
, 16-bit word length, and best-precision fraction length.a = ufi(v,w)
returns an unsigned fixed-point object with valuev
, word lengthw
, and best-precision fraction length.a = ufi(v,w,f)
returns an unsigned fixed-point object with valuev
, word lengthw
, and fraction lengthf
.a = ufi(v,w,slope,bias)
returns an unsigned fixed-point object with valuev
, word lengthw
,slope
, andbias
.a = ufi(v,w,slopeadjustmentfactor,fixedexponent,bias)
returns an unsigned fixed-point object with valuev
, word lengthw
,slopeadjustmentfactor
,fixedexponent
, andbias
.
fi
objects created by the ufi
constructor
function have the following general types of properties:
These properties are described in detail in fi Object Properties in the Properties Reference.
Note
fi
objects created by the ufi
constructor
function have no local fimath.
Data Properties
The data properties of a fi
object are always
writable.
bin
— Stored integer value of afi
object in binarydata
— Numerical real-world value of afi
objectdec
— Stored integer value of afi
object in decimaldouble
— Real-world value of afi
object, stored as a MATLAB®double
hex
— Stored integer value of afi
object in hexadecimalint
— Stored integer value of afi
object, stored in a built-in MATLAB integer data type. You can also useint8
,int16
,int32
,int64
,uint8
,uint16
,uint32
, anduint64
to get the stored integer value of afi
object in these formatsoct
— Stored integer value of afi
object in octal
These properties are described in detail in fi Object Properties.
fimath Properties
When you create a fi
object with the ufi
constructor
function, that fi
object does not have a local
fimath
object. You can attach a fimath
object to that fi
object if you do not want to use the default
fimath settings. For more information, see fimath Object Construction.
fimath
— fixed-point math object
The following fimath
properties are always
writable and, by transitivity, are also properties of a fi
object.
CastBeforeSum
— Whether both operands are cast to the sum data type before additionNote
This property is hidden when the
SumMode
is set toFullPrecision
.OverflowAction
— Action to take on overflowProductBias
— Bias of the product data typeProductFixedExponent
— Fixed exponent of the product data typeProductFractionLength
— Fraction length, in bits, of the product data typeProductMode
— Defines how the product data type is determinedProductSlope
— Slope of the product data typeProductSlopeAdjustmentFactor
— Slope adjustment factor of the product data typeProductWordLength
— Word length, in bits, of the product data typeRoundingMethod
— Rounding methodSumBias
— Bias of the sum data typeSumFixedExponent
— Fixed exponent of the sum data typeSumFractionLength
— Fraction length, in bits, of the sum data typeSumMode
— Defines how the sum data type is determinedSumSlope
— Slope of the sum data typeSumSlopeAdjustmentFactor
— Slope adjustment factor of the sum data typeSumWordLength
— The word length, in bits, of the sum data type
These properties are described in detail in fimath Object Properties.
numerictype Properties
When you create a fi
object, a numerictype
object
is also automatically created as a property of the fi
object.
numerictype
— Object containing all
the data type information of a fi
object, Simulink® signal
or model parameter
The following numerictype
properties are,
by transitivity, also properties of a fi
object.
The properties of the numerictype
object become
read only after you create the fi
object. However,
you can create a copy of a fi
object with new values
specified for the numerictype
properties.
Bias
— Bias of afi
objectDataType
— Data type category associated with afi
objectDataTypeMode
— Data type and scaling mode of afi
objectFixedExponent
— Fixed-point exponent associated with afi
objectSlopeAdjustmentFactor
— Slope adjustment associated with afi
objectFractionLength
— Fraction length of the stored integer value of afi
object in bitsScaling
— Fixed-point scaling mode of afi
objectSigned
— Whether afi
object is signed or unsignedSignedness
— Whether afi
object is signed or unsignedNote
numerictype
objects can have aSignedness
ofAuto
, but allfi
objects must beSigned
orUnsigned
. If anumerictype
object withAuto
Signedness
is used to create afi
object, theSignedness
property of thefi
object automatically defaults toSigned
.Slope
— Slope associated with afi
objectWordLength
— Word length of the stored integer value of afi
object in bits
For further details on these properties, see numerictype Object Properties.
Examples
Note
For information about the display format of fi
objects,
refer to View Fixed-Point Data.
For examples of casting, see Cast fi Objects.
Example 1
For example, the following creates an unsigned
fi
object with a value of pi
, a word
length of 8 bits, and a fraction length of 3 bits:
a = ufi(pi,8,3)
a = 3.1250 DataTypeMode: Fixed-point: binary point scaling Signedness: Unsigned WordLength: 8 FractionLength: 3
Default fimath
properties are associated with
a
. When a fi
object does not have
a local fimath
object, no fimath
object properties are displayed in its output. To determine whether a
fi
object has a local fimath
object, use the isfimathlocal
function.
isfimathlocal(a)
ans = 0
A returned value of 0
means the fi
object does not have a local fimath
object. When the
isfimathlocal
function returns a
1
, the fi
object has a local
fimath
object.
Example 2
The value v
can also be an array:
a = ufi((magic(3)/10),16,12)
a = 0.8000 0.1001 0.6001 0.3000 0.5000 0.7000 0.3999 0.8999 0.2000 DataTypeMode: Fixed-point: binary point scaling Signedness: Unsigned WordLength: 16 FractionLength: 12
Example 3
If you omit the argument f
, it is set
automatically to the best precision possible:
a = ufi(pi,8)
a = 3.1406 DataTypeMode: Fixed-point: binary point scaling Signedness: Unsigned WordLength: 8 FractionLength: 6
Example 4
If you omit w
and f
,
they are set automatically to 16 bits and the best precision possible,
respectively:
a = ufi(pi)
a = 3.1416 DataTypeMode: Fixed-point: binary point scaling Signedness: Unsigned WordLength: 16 FractionLength: 14
Extended Capabilities
Version History
Introduced in R2009b
See Also
fi
| fimath
| fipref
| isfimathlocal
| numerictype
| quantizer
| sfi