Main Content

half

Construct half-precision numeric object

Description

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.

Creation

Description

example

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
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
cospiCompute cos(X*pi) accurately
dotDot product
expExponential
expm1Compute exp(x)-1 accurately for small values of 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
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 log(1+x) accurately for small values of x
meanAverage or mean value of array
minusSubtraction
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
plusAddition or append strings
pow10Base 10 power and scale half-precision numbers
pow2Base 2 power and scale 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
timesMultiplication
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 uses complex storage
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
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
catConcatenate arrays
circshiftShift array circularly
colonVector creation, array subscripting, and for-loop iteration
complexCreate complex array
ctransposeComplex conjugate transpose
eyeIdentity matrix
flipFlip order of elements
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
permutePermute array dimensions
repelemRepeat copies of array elements
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
areaArea of 2-D alpha shape
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
activations (Deep Learning Toolbox)Compute deep learning network layer activations
classify (Deep Learning Toolbox)Classify data using a trained deep learning neural network
predict (Deep Learning Toolbox)Reconstruct the inputs using trained autoencoder
predictAndUpdateState (Deep Learning Toolbox)Predict responses using a trained recurrent neural network and update the network state

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

methods(half(1))

Examples

collapse all

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

a = half(pi)
a = 

  half

    3.1406

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

Limitations

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

  • rsqrt

  • fma

Extended Capabilities

Introduced in R2018b