Q:

Why ceil function of matlab and java are different?

I am using ceil function in JAVA. I would like to compare that function with MATLAB. However, it returns different value when I use it in MATLAB. For example, I have H=7, I use that code in JAVA
int H=7;
double Hp= Math.ceil(H/2);

It returns 3. 
However, I use that function in MATLAB
Hp= ceil(H/2);

It returns 4. What is true in here? How to achieve the result similar ceil function in JAVA? Thank you in advance

A:

To answer "How to achieve the result similar ceil function in JAVA?", you can use idivide with an integer cast on one of the arguments:
H  = 7;
Hp = idivide(H,int8(2));

This will perform the division and round the fractional part toward 0 by default.  The ceil function is unnecessary since integer division generates integers.  You can wrap this in a ceil but nothing will happen.

Note: The use of idivide is required since MATLAB's implementation of integer arithmetic (quite counter-intuitively in my experience) actually rounds the fractional portion of an integer division to the nearest integer (at least on R2014b):
Hp = int8(7) /int8(2) ; % 3.5 float => 4 integer
Hp = int8(34)/int8(10); % 3.4 float => 3 integer

I suspect this has to do with some type casting by the rdivide function.

