double DataType for images in MATLAB

Viewed 92

a question has been on my mind :

Why should we use double datatype for the image In MATLAB programming language ?

1 Answers

For historical reasons, all numeric values in Matlab default to being double. Originally, double was the only numeric type that Matlab supported. Integer types were grafted on later, and in an attempt to preserve back-compatibility, they were defined with unusual behavior: mixed-type arithmetic operations between floating-point and integer types in Matlab implicitly narrow to the integer type. (Because in Matlab, numeric literals like 1234 that look like integers actually produce doubles.) In pretty much every other programming language, mixed-type arithmetic operations implicitly widen to the floating-point type.

This implicit narrowing behavior makes it easy to write Matlab code that quietly produces bad results if you have integer values anywhere. So most Matlab programmers, and most Matlab programs, just use doubles for everything.

Related