Construct half-precision numeric object


Use the half constructor to assign a half-precision data type to a number or variable. A half-precision data type occupies 16 bits of memory, but its floating-point representation enables it to handle wider dynamic ranges than integer or fixed-point data types of the same size.

For more information, see Floating-Point Numbers.




a = half(v) converts the values in v to half-precision.

Input Arguments

expand all

Input array, specified as a scalar, vector, matrix, or multidimensional array.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical
Complex Number Support: Yes

Object Functions

These functions are supported for use with half-precision inputs.

expand all

absAbsolute value and complex magnitude
acosInverse cosine in radians
asinInverse sine in radians
atanhInverse hyperbolic tangent
ceilRound toward positive infinity
convConvolution and polynomial multiplication
conv22-D convolution
cosCosine of argument in radians
cospiCompute cos(X*pi) accurately
dotDot product
expm1Compute exp(x)-1 accurately for small values of x
fixRound toward zero
floorRound toward negative infinity
fmaMultiply and add using fused multiply add approach
hypotSquare root of sum of squares (hypotenuse)
ldivideLeft array division
logNatural logarithm
log1pCompute log(1+x) accurately for small values of x
meanAverage or mean value of array
modRemainder after division (modulo operation)
mtimesMatrix multiplication
pow10Base 10 power and scale half-precision numbers
pow2Base 2 power and scale floating-point numbers
prodProduct of array elements
rdivideRight array division
remRemainder after division
roundRound to nearest decimal or integer
rsqrtReciprocal square root
sinSine of argument in radians
sinpiCompute sin(X*pi) accurately
sqrtSquare root
sumSum of array elements
tanhHyperbolic tangent
uminusUnary minus
uplusUnary plus
castConvert variable to different data type
cellCell array
doubleDouble-precision arrays
epsFloating-point relative accuracy
InfCreate array of all Inf values
int1616-bit signed integer arrays
int3232-bit signed integer arrays
int6464-bit signed integer arrays
int88-bit signed integer arrays
isaDetermine if input has specified data type
isfloatDetermine whether input is floating-point data type
islogicalDetermine if input is logical array
isnanDetermine which array elements are NaN
isnumericDetermine whether input is numeric array
isrealDetermine whether array is real
logicalConvert numeric values to logicals
NaNCreate array of all NaN values
singleSingle-precision arrays
uint1616-bit unsigned integer arrays
uint3232-bit unsigned integer arrays
uint6464-bit unsigned integer arrays
uint88-bit unsigned integer arrays
allDetermine if all array elements are nonzero or true
andFind logical AND
anyDetermine if any array elements are nonzero
eqDetermine equality
geDetermine greater than or equal to
gtDetermine greater than
leDetermine less than or equal to
ltDetermine less than
neDetermine inequality
notFind logical NOT
orFind logical OR
catConcatenate arrays
colonVector creation, array subscripting, and for-loop iteration
eyeIdentity matrix
fullConvert sparse matrix to full storage
horzcatHorizontal concatenation for heterogeneous arrays
iscolumnDetermine whether input is column vector
isemptyDetermine whether array is empty
isfiniteDetermine which array elements are finite
isinfDetermine which array elements are infinite
ismatrixDetermine whether input is matrix
isrowDetermine whether input is row vector
isscalarDetermine whether input is scalar
isvectorDetermine whether input is vector
lengthLength of largest array dimension
maxMaximum elements of an array
minMinimum elements of an array
ndimsNumber of array dimensions
numelNumber of array elements
onesCreate array of all ones
repmatRepeat copies of array
reshapeReshape array
sizeArray size
subsasgnRedefine subscripted assignment
subsrefSubscripted reference
transposeTranspose vector or matrix
vertcatVertical concatenation for heterogeneous arrays
zerosCreate array of all zeros
displayShow information about variable or result of expression
endTerminate block of code or indicate last array index
barBar graph
barhHorizontal bar graph
fplotPlot expression or function
lineCreate primitive line
plot2-D line plot
plot33-D point or line plot
plotmatrixScatter plot matrix
rgbplotPlot colormap
scatterScatter plot
scatter33-D scatter plot
xlimSet or query x-axis limits
ylimSet or query y-axis limits
zlimSet or query z-axis limits


collapse all

To cast a double-precision number to half precision, use the half function.

a = half(pi)
a = 



You can also use the half function to cast an existing variable to half-precision.

v = single(magic(3))
v = 3x3 single matrix

     8     1     6
     3     5     7
     4     9     2

a = half(v)
a = 

  3x3 half matrix

     8     1     6
     3     5     7
     4     9     2


The following functions which support half-precision inputs, do not support complex half-precision inputs.

  • rsqrt

  • fma

Extended Capabilities

See Also



Introduced in R2018b