Main Content


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 and What is Half Precision?.

For a list of functions that support code generation with half-precision inputs, see Half Precision Code Generation Support.




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 simulation with half-precision inputs in MATLAB®. MATLAB System object™ supports half-precision data type and MATLAB System block supports half-precision data type with real values. For a list of functions that support code generation with half-precision inputs, see Half Precision Code Generation Support.

expand all

absAbsolute value and complex magnitude
acosInverse cosine in radians
acoshInverse hyperbolic cosine
asinInverse sine in radians
asinhInverse hyperbolic sine
atanInverse tangent in radians
atan2Four-quadrant inverse tangent
atanhInverse hyperbolic tangent
ceilRound toward positive infinity
conjComplex conjugate
convConvolution and polynomial multiplication
conv22-D convolution
cosCosine of argument in radians
coshHyperbolic cosine
cospiCompute cos(X*pi) accurately
cumsumCumulative sum
dotDot product
expm1Compute exp(X)-1 accurately for small X
fftFast Fourier transform
fft22-D fast Fourier transform
fftnN-D fast Fourier transform
fftshiftShift zero-frequency component to center of spectrum
fixRound toward zero
fixed.interp11-D data interpolation (table lookup)
fixed.interp2Interpolation for 2-D gridded data in meshgrid format
fixed.interp3Interpolation for 3-D gridded data in meshgrid format
fixed.interpnInterpolation for 1-D, 2-D, 3-D, and N-D gridded data in ndgrid format
floorRound toward negative infinity
fmaMultiply and add using fused multiply add approach
hypotSquare root of sum of squares (hypotenuse)
ifftInverse fast Fourier transform
ifft22-D inverse fast Fourier transform
ifftnMultidimensional inverse fast Fourier transform
ifftshiftInverse zero-frequency shift
imagImaginary part of complex number
ldivideLeft array division
logNatural logarithm
log10Common logarithm (base 10)
log1pCompute natural logarithm of 1+X accurately for small X
log2Base 2 logarithm and floating-point number dissection
meanAverage or mean value of array
mldivideSolve systems of linear equations Ax = B for x
modRemainder after division (modulo operation)
mrdivideSolve systems of linear equations xA = B for x
mtimesMatrix multiplication
plusAdd numbers, append strings
pow10Base 10 power and scale half-precision numbers
pow2Base 2 exponentiation and scaling of floating-point numbers
powerElement-wise power
prodProduct of array elements
rdivideRight array division
realReal part of complex number
remRemainder after division
roundRound to nearest decimal or integer
rsqrtReciprocal square root
signSign function (signum function)
sinSine of argument in radians
sinhHyperbolic sine
sinpiCompute sin(X*pi) accurately
sqrtSquare root
sumSum of array elements
tanTangent of argument in radians
tanhHyperbolic tangent
uminusUnary minus
uplusUnary plus
allfiniteDetermine if all array elements are finite
anynanDetermine if any array element is NaN
castConvert variable to different data type
cellCell array
doubleDouble-precision arrays
epsFloating-point relative accuracy
flintmaxLargest consecutive integer in floating-point format
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
isintegerDetermine whether input is integer array
islogicalDetermine if input is logical array
isnanDetermine which array elements are NaN
isnumericDetermine whether input is numeric array
isobjectDetermine if input is MATLAB object
isrealDetermine whether array uses complex storage
logicalConvert numeric values to logicals
NaNCreate array of all NaN values
realmaxLargest positive floating-point number
realminSmallest normalized floating-point number
singleSingle-precision arrays
storedIntegerStored integer value of fi object
typecastConvert data type without changing underlying data
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
Short-Circuit ANDLogical AND with short-circuiting
anyDetermine if any array elements are nonzero
eqDetermine equality
geDetermine greater than or equal to
gtDetermine greater than
isequalDetermine array equality
isequalnDetermine array equality, treating NaN values as equal
leDetermine less than or equal to
ltDetermine less than
neDetermine inequality
notFind logical NOT
orFind logical OR
Short-Circuit ORLogical OR with short-circuiting
catConcatenate arrays
cholCholesky factorization
circshiftShift array circularly
colonVector creation, array subscripting, and for-loop iteration
complexCreate complex array
ctransposeComplex conjugate transpose
emptyCreate empty array of specified class
eyeIdentity matrix
flipFlip order of elements
fliplrFlip array left to right
flipudFlip array up to down
horzcatHorizontal concatenation for heterogeneous arrays
iscolumnDetermine if 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 if input is row vector
isscalarDetermine whether input is scalar
issortedDetermine if array is sorted
isvectorDetermine whether input is vector
lengthLength of largest array dimension
luLU matrix factorization
maxMaximum elements of array
minMinimum elements of array
ndimsNumber of array dimensions
numelNumber of array elements
onesCreate array of all ones
permutePermute array dimensions
repelemRepeat copies of array elements
repmatRepeat copies of array
reshapeReshape array by rearranging existing elements
sizeArray size
sortSort array elements
squeezeRemove dimensions of length 1
transposeTranspose vector or matrix
vertcatVertically concatenate for heterogeneous arrays
zerosCreate array of all zeros
areaArea of 2-D alpha shape
barBar graph
barhHorizontal bar graph
fplotPlot expression or function
lineCreate primitive line
plot2-D line plot
plot33-D 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
activations (Deep Learning Toolbox)(Not recommended) Compute deep learning network layer activations
classify (Deep Learning Toolbox)(Not recommended) Classify data using trained deep learning neural network
predict (Deep Learning Toolbox)Reconstruct the inputs using trained autoencoder
predictAndUpdateState (Deep Learning Toolbox)(Not recommended) Predict responses using a trained recurrent neural network and update the network state

To display a list of supported functions, at the MATLAB Command Window, enter:



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


Extended Capabilities

Version History

Introduced in R2018b