Arithmetic promotion: floating-point to integer?

Hi,

[quote “MATLAB — Programming Fundamentals R2011b.pdf”] Arithmetic operations that involve both integers and floating-point always result in an integer data type. MATLAB rounds the result, when necessary, according to the default rounding algorithm. The example below yields an exact answer of 1426.75 which MATLAB then rounds to the next highest integer:

int16(325) * 4.39
ans =
1427

[/quote]

In C/C++, the arithmetic promotion rule is to upper ↑: char to int, int unsigned int, int to float, float to double, etc.

Why Matlab designs to be to lower (int)?

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

Since I work in code generation, these sorts of behaviors are a regular nuisance to me, but maybe I can imagine why. In MATLAB, most users do almost everything with doubles. When programming in MATLAB language, the average user doesn’t even think about numeric types. I wasn’t around then, but I think integers were originally added to the language primarily because it was burdensome to represent things like images as large arrays of doubles. Having added integers to the language to save on storage, you wouldn’t want something simple like multiplying a large int8 array by 2 (that’s double precision 2.0 in MATLAB) to generate a large double precision array out of a large integer array.

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store