superiorfloat

Class name of the dominant floating-point type among the arguments.

Category: Other public functions: datatypes

Syntax

cls = superiorfloat(a, b, ...)

Returns 'single' if any argument is single, otherwise 'double'.

Description

The result follows the rule that arithmetic between single and double gives single. It is used when writing a function that should produce the same precision as its inputs, for example by creating the output with zeros(n, cls).

An argument of any other class, such as an integer type or a char, is an error.

Input arguments

a, b, ...
Floating-point arrays (single or double).

Output arguments

cls
Character vector, 'single' or 'double'.

Example

Mixed precisions

superiorfloat(1, 2)
superiorfloat(single(1), 2)
try
    superiorfloat(int8(1))
catch err
    disp(err.message)
end
Output
ans = 'double'
ans = 'single'
Inputs must be floats, namely single or double.

See also

class single double isfloat