half

Construct half-precision numeric object

Description

Use the half constructor to assign a half-precision data type to a number or variable. Half-precision data types occupy only 16 bits of memory, but their floating-point representation enables them 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
ceilRound toward positive infinity
cosCosine of argument in radians
cospiCompute cos(X*pi) accurately
dotDot product
expExponential
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
minusSubtraction
modRemainder after division (modulo operation)
mtimesMatrix multiplication
plusAddition
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
timesMultiplication
uminusUnary minus
uplusUnary plus
castConvert variable to different data type
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
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
catConcatenate arrays
colonVector creation, array subscripting, and for-loop iteration
eyeIdentity matrix
fullConvert sparse matrix to full storage
horzcatHorizontal concatenation for heterogeneous arrays
isemptyDetermine whether array is empty
isfiniteDetermine which array elements are finite
isinfDetermine which array elements are infinite
isscalarDetermine whether input is scalar
isvectorDetermine whether input is vector
lengthLength of largest array dimension
minMinimum of timeseries data
maxMaximum of timeseries data
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 expression result
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

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

Introduced in R2018b