single
Converts values to single-precision floating point.
Category: Language Fundamentals > Data Types
Syntax
B = single(A)
Converts A to class single, 32 bits per element.
Description
Single precision has about 7 decimal digits and a range up to about 3.4e38, against 15 or 16 digits and 1.8e308 for double. Values that do not fit are rounded: single(16777217) becomes 16777216. Arithmetic that mixes single and double gives single, and mixing single with an integer type gives that integer type.
Using single halves memory use, which matters for large arrays.
Input arguments
A- Numeric, logical or char array.
Output arguments
B- Array of the same size with class
single.
Example
single(pi)
class(single(1) + 1)
single(16777217)
class(single(1) * int8(2))
Output
ans = single
3.1416
ans = 'single'
ans = single
16777216
ans = 'int8'