billgray1234
Programmer
- Mar 14, 2011
- 39
i have a few questions about a program i'm writing in fortran 90. i've written a few explanation notes below, followed by my questions.
PRECISION IN FORTRAN 90
to enable portability between different computers, i'm declaring real variables using the KIND parameter, according to
integer, parameter :: PR = selected_real_kind(p=N)
real(KIND=PR) :: x
where PR stands for 'Precision of Real numbers', x is a real variable, and N could be 4, 8, 15, etc.
INTRINSIC FUNCTIONS
i want to use intrinsic functions (such as SIN, EXP, ABS).
INTRINSIC FUNCTIONS AND PRECISION
to my understanding, each of the above intrinsic functions has several 'versions', depending on the level of precision. these versions include 1) single precision, 2) double precision, and, on some computers, 3) even higher precision. for example:-
SIN(x) -- single precision is SIN(x), double precision is DSIN(x)
EXP(x) -- single precision is EXP(x), double precision is DEXP(x)
and so on.
i think 'single precision' functions are called GENERIC functions, whereas 'double precision' functions are called SPECIFIC functions. also, to my understanding, the 'level of precision' in these intrinsic functions refers to the level of precision of the argument (i.e. x) and the result computed (please correct me if i'm wrong about this).
MY SITUATION
let's say i'm writing my program on computer 1. i know 'in advance' what level of precision computer 1 is capable of. for example, let's say it's capable of higher precision than just single precision (e.g. N=15 above), such that it's capable of using the double precision versions of the intrinsic functions (i.e. DSIN, DEXP, DABS, etc).
but, now i want to compile/run my program on another computer (computer 2, say). i don't know 'in advance' what level of precision computer 2 is capable of -- it might only be capable of a much lower level precision than computer 1 is capable of (e.g. it might only support N=4 above).
MY QUESTIONS
1) when i write my program on computer 1, which 'versions' of the intrinsic functions should i use -- single precision (i.e. SIN, EXP, ABS, etc) or double precision (i.e. DSIN, DEXP, DABS, etc)?
2) in general, if i don't know 'in advance' what level of precision a computer is capable of, then which 'versions' of the intrinsic functions should i use -- single precision or double precision?
3) if x is declared as being high precision (e.g. N=15), but i only use single precision intrinsic functions (i.e. SIN, EXP, ABS, etc), then will each function 'result' be single precision or double precision? in other words, is the level of precision controlled by the variable declaration statement -- or by the intrinsic function?
any help would be appreciated.
PRECISION IN FORTRAN 90
to enable portability between different computers, i'm declaring real variables using the KIND parameter, according to
integer, parameter :: PR = selected_real_kind(p=N)
real(KIND=PR) :: x
where PR stands for 'Precision of Real numbers', x is a real variable, and N could be 4, 8, 15, etc.
INTRINSIC FUNCTIONS
i want to use intrinsic functions (such as SIN, EXP, ABS).
INTRINSIC FUNCTIONS AND PRECISION
to my understanding, each of the above intrinsic functions has several 'versions', depending on the level of precision. these versions include 1) single precision, 2) double precision, and, on some computers, 3) even higher precision. for example:-
SIN(x) -- single precision is SIN(x), double precision is DSIN(x)
EXP(x) -- single precision is EXP(x), double precision is DEXP(x)
and so on.
i think 'single precision' functions are called GENERIC functions, whereas 'double precision' functions are called SPECIFIC functions. also, to my understanding, the 'level of precision' in these intrinsic functions refers to the level of precision of the argument (i.e. x) and the result computed (please correct me if i'm wrong about this).
MY SITUATION
let's say i'm writing my program on computer 1. i know 'in advance' what level of precision computer 1 is capable of. for example, let's say it's capable of higher precision than just single precision (e.g. N=15 above), such that it's capable of using the double precision versions of the intrinsic functions (i.e. DSIN, DEXP, DABS, etc).
but, now i want to compile/run my program on another computer (computer 2, say). i don't know 'in advance' what level of precision computer 2 is capable of -- it might only be capable of a much lower level precision than computer 1 is capable of (e.g. it might only support N=4 above).
MY QUESTIONS
1) when i write my program on computer 1, which 'versions' of the intrinsic functions should i use -- single precision (i.e. SIN, EXP, ABS, etc) or double precision (i.e. DSIN, DEXP, DABS, etc)?
2) in general, if i don't know 'in advance' what level of precision a computer is capable of, then which 'versions' of the intrinsic functions should i use -- single precision or double precision?
3) if x is declared as being high precision (e.g. N=15), but i only use single precision intrinsic functions (i.e. SIN, EXP, ABS, etc), then will each function 'result' be single precision or double precision? in other words, is the level of precision controlled by the variable declaration statement -- or by the intrinsic function?
any help would be appreciated.