scana
scana

Reputation: 111

fortran integer to double

I have a doubt about fortran. In the following code:

program p
integer num
real*8 d
num=111
d=dble(num/4) 
print*, d 
end program p

I get 27.000000000000000. Is it because num is an integer and so num/4 have to be the same type? It is a part of another code I have to translate in Matlab: in this particular case can I translate it as num/4 truncated?

floor(num/4)

Thank you in advance

Upvotes: 0

Views: 5412

Answers (1)

MDH
MDH

Reputation: 132

Yes, you get 27.000000000000000 because num is an integer, thus num\4 is an integer.

To get a real precision result, you would simply write d=1./4*num

Yes, in Matlab this would be floor(num/4) as num is a double precision float unless you specify otherwise.

Upvotes: 2

Related Questions