Creating Single Floating Point and Double Floating Point in MATLAB
Single Precision:
As MATLAB creates double precision floating point number by default, we use single() function to create single precision floating point number.
Example 1:
Matlab
% MATLAB code for creating single precision floating point num = single(123.45); % verifying the attributes of num by whose function whose( "num" ) |
Output:
Double Precision:
Double precision floating point numbers can be created by ordinary assignment or using the double function.
Example 2:
Matlab
% MATLAB code for creating number by double function num = double(123.45); % Creating number by ordinary assignment num_assignment = 678.9; % Checking the attributes of both variables whose( "num" , "num_assignment" ) |
Output:
As it can be seen, both num and num_assignment variables have same attributes of double type.
Matlab Floating Point Precision
Numeric class in MATLAB includes signed and unsigned integers, single-precision floating-point numbers, and double-precision floating-point numbers. Generally, MATLAB stores all numeric values as double-precision floating-point.Floating Point Numbers in MATLAB are stored in two forms:
- Single Precision Floating point
- Double Precision Floating point
MATLAB keeps the double precision floating point as the default floating point representation however, it can be changed to single by a very simple function.
Contact Us