fortran90 - CEILING and FLOOR function in Fortran - aren't they supposed to return INTEGERS? -
a quick question regarding ceiling , floor functions in fortran 90/95.
based on documentation: https://gcc.gnu.org/onlinedocs/gfortran/ceiling.html
my impression take in reals, return integers. however, example, simple program, get:
program example real:: x=-3.4 nintx = nint(x) ceilx = ceiling(x) floorx = floor(x) write(*,*) nintx, ceilx, floorx end program i -3, -3.00000 , -4.00000. based on documentation return types integers. why ceiling , floor results displayed decimal point , trailing zeros?
ceiling , floor return integer results. however, not printing results: printing variables celix , floorx of real type.
those variables real because of implicit typing. contrast nintx indeed integer variable.
list-directed output (the write(*,*) part) has natural result formatting real variables see. if instead directly print function results
write(*,*) nint(x), ceiling(x), floor(x) you less surprised.
the obvious thing is: don't use implicit typing. have second line implicit none.
Comments
Post a Comment