[CSC 435] Fortran Intrinisics

Andrew Pounds pounds_aj at mercer.edu
Thu Feb 11 08:39:12 EST 2016


So now that some of you are tuning your dusty deck code you are starting 
to notice that you are getting different results.  One place that this 
creeps in is with the use of Fortran intrinsic functions (like cos and 
sin).  By default these intrinsic functions return values that are the 
same TYPE as their argument.

If x is a (kind=4) real and y is a (kind=2) real then

cos(x)

returns a real (kind=4) and

cos(y)

returns a real (kind=2)

You can force the return type to a higher precision by calling the 
double precision analogues

dcos(x)

and to force it to a lower precision you can typecast it

real(cos(x))

dble(cos(y)) I presume would return a value but I have no idea if the 
low order bits in the floating point number were zeros or junk.






More information about the csc435 mailing list