MATLAB: Format short and format long

variable

I need to find the relative error between 2 variable, the one in format short and the other in format long. How can I take the same variable, once in short and once in long so I can subtract the two?

Best Answer

If you have one variable that is single precision and one that is double precision, you can perform your calculation with them as you normally would. The result will be single precision.
According to the documentation on Floating-Point Numbers, specifically Single-Precision Operations:
  • You can perform basic arithmetic operations with single and any of the following other classes. The result is always single:
single
double
char
logical