Main Content

一半

Construct half-precision numeric object

Description

Use the一半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, seeFloating-Point Numbers(Fixed-Point Designer).

Creation

Syntax

Description

example

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

Input Arguments

expand all

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

Data Types:single|double|我nt8|我nt16|我nt32|我nt64|uint8|uint16|uint32|uint64|logical
Complex Number Support:Yes

Object Functions

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

expand all

abs Absolute value and complex magnitude
acos Inverse cosine in radians
acosh Inverse hyperbolic cosine
asin Inverse sine in radians
asinh Inverse hyperbolic sine
atan Inverse tangent in radians
atan2 Four-quadrant inverse tangent
atanh Inverse hyperbolic tangent
ceil Round toward positive infinity
conj Complex conjugate
conv Convolution and polynomial multiplication
conv2 2-D convolution
cos Cosine of argument in radians
cospi Compute cos(X*pi) accurately
dot Dot product
exp Exponential
expm1 Compute exp(x)-1 accurately for small values of x
fft Fast Fourier transform
fft2 2-D fast Fourier transform
fftn N-D fast Fourier transform
fftshift Shift zero-frequency component to center of spectrum
fix Round toward zero
floor Round toward negative infinity
fma(Fixed-Point Designer) Multiply and add using fused multiply add approach
hypot Square root of sum of squares (hypotenuse)
我fft Inverse fast Fourier transform
我fft2 2-D inverse fast Fourier transform
我fftn Multidimensional inverse fast Fourier transform
我fftshift Inverse zero-frequency shift
我mag Imaginary part of complex number
ldivide Left array division
log Natural logarithm
log10 Common logarithm (base 10)
log1p Compute log(1+x) accurately for small values of x
mean Average or mean value of array
minus Subtraction
mldivide Solve systems of linear equationsAx = Bforx
mod Remainder after division (modulo operation)
mrdivide Solve systems of linear equationsxA = Bforx
mtimes Matrix multiplication
plus Addition or append strings
pow10(Fixed-Point Designer) Base 10 power and scale half-precision numbers
pow2 Base 2 power and scale floating-point numbers
power Element-wise power
prod Product of array elements
rdivide Right array division
real Real part of complex number
rem Remainder after division
round Round to nearest decimal or integer
rsqrt(Fixed-Point Designer) Reciprocal square root
sign Sign function (signum function)
sin Sine of argument in radians
sinh Hyperbolic sine
sinpi Compute sin(X*pi) accurately
sqrt Square root
sum Sum of array elements
tan Tangent of argument in radians
tanh Hyperbolic tangent
times Multiplication
uminus Unary minus
uplus Unary plus
cast Convert variable to different data type
cell Cell array
double Double-precision arrays
eps Floating-point relative accuracy
Inf Create array of allInfvalues
我nt16 16-bit signed integer arrays
我nt32 32-bit signed integer arrays
我nt64 64-bit signed integer arrays
我nt8 8-bit signed integer arrays
我sa Determine if input has specified data type
我sfloat(Fixed-Point Designer) Determine whether input is floating-point data type
我slogical Determine if input is logical array
我snan Determine which array elements are NaN
我snumeric Determine whether input is numeric array
我sreal Determine whether array uses complex storage
logical Convert numeric values to logicals
NaN Create array of allNaNvalues
single Single-precision arrays
uint16 16-bit unsigned integer arrays
uint32 32-bit unsigned integer arrays
uint64 64-bit unsigned integer arrays
uint8 8-bit unsigned integer arrays
all Determine if all array elements are nonzero ortrue
and Find logical AND
any Determine if any array elements are nonzero
eq Determine equality
ge Determine greater than or equal to
gt Determine greater than
我sequal 确定数组平等
我sequaln 确定数组平等, treating NaN values as equal
le Determine less than or equal to
lt Determine less than
ne Determine inequality
not Find logical NOT
or Find logical OR
cat Concatenate arrays
circshift Shift array circularly
colon Vector creation, array subscripting, andfor-loop iteration
complex Create complex array
ctranspose Complex conjugate transpose
eye Identity matrix
flip Flip order of elements
full Convert sparse matrix to full storage
horzcat Horizontal concatenation for heterogeneous arrays
我scolumn Determine whether input is column vector
我sempty Determine whether array is empty
我sfinite Determine which array elements are finite
我sinf Determine which array elements are infinite
我smatrix Determine whether input is matrix
我srow Determine whether input is row vector
我sscalar Determine whether input is scalar
我svector Determine whether input is vector
length Length of largest array dimension
max Maximum elements of an array
min Minimum elements of an array
ndims Number of array dimensions
numel Number of array elements
ones Create array of all ones
permute Permute array dimensions
repelem Repeat copies of array elements
repmat Repeat copies of array
reshape Reshape array
size Array size
subsasgn Redefine subscripted assignment
subsref Subscripted reference
transpose Transpose vector or matrix
vertcat Vertical concatenation for heterogeneous arrays
zeros Create array of all zeros
display Show information about variable or result of expression
area Area of 2-D alpha shape
bar Bar graph
barh Horizontal bar graph
fplot Plot expression or function
line Create primitive line
plot 2-D line plot
plot3 3-D point or line plot
plotmatrix Scatter plot matrix
rgbplot Plot colormap
scatter Scatter plot
scatter3 3-D scatter plot
xlim Set or queryx-axis limits
ylim Set or queryy-axis limits
zlim Set or queryz-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一半function.

a = half(pi)
a = half 3.1406

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

v = single(magic(3))
v =3x3 single matrix8 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