Prev: Programmer's Paradise
Next: Reading a .wav file
From: monir on 9 Aug 2010 10:17 Hello; Suppose one needs to use a higher precision than "double-precision" reals. 1) How does one determine if a PC has a kind type that supports a "triple-precision" or "quadruple-precision" or even higher ?? 2) Can one type a simple DOS command to determine the highest precision available on a particular m/c (Win XP) ?? 3) Is it possible to use an F90 intrinsic function (if available) to automatically assign reals to the highest precision (for portability) ?? (something similar to using TINY() or EPSILON() in a numerical model) Thank you. Monir
From: dpb on 9 Aug 2010 14:00 monir wrote: > Hello; > > Suppose one needs to use a higher precision than "double-precision" > reals. > 1) How does one determine if a PC has a kind type that supports a > "triple-precision" or "quadruple-precision" or even higher ?? > 2) Can one type a simple DOS command to determine the highest > precision available on a particular m/c (Win XP) ?? > 3) Is it possible to use an F90 intrinsic function (if available) to > automatically assign reals to the highest precision (for > portability) ?? > (something similar to using TINY() or EPSILON() in a numerical model) Those are the uses of SELECTED_REAL_KIND() and PRECISION() There have been posted modules on clf previously for suggestions of generic usage/determinations... --
From: monir on 9 Aug 2010 15:19 On Aug 9, 2:00 pm, dpb <n...(a)non.net> wrote: > Those are the uses of SELECTED_REAL_KIND() and PRECISION() > > There have been posted modules on clf previously for suggestions of > generic usage/determinations... > 1) So to specify a desired precision one may use something like: ....INTEGER, PARAMETER :: EP = SELECTED_REAL_KIND(35) ....REAL (KIND = EP) :: X, Y to declare the variables X and Y to be REAL floating-point variables with 35 decimal digits accuracy. But such desired precision may not be available on a particular m/c. Would such declaration result in a compiler error ?? Or would the compiler (g95) simply ignore it and assign whatever (lower) precision available ?? 2) On the other hand, the intrinsic PRECISION(X) returns the property (i.e.; precision) of X. But this is after the fact! One still has to know the highest precision available for consistency and portability. Correct ?? It might be possible to combine SELECTED_REAL_KIND() with PRECISION(). Will continue searching this cfl for directly relevant posts as per your suggestion. Regards. Monir
From: dpb on 9 Aug 2010 15:35 monir wrote: > On Aug 9, 2:00 pm, dpb <n...(a)non.net> wrote: >> Those are the uses of SELECTED_REAL_KIND() and PRECISION() >> >> There have been posted modules on clf previously for suggestions of >> generic usage/determinations... >> > > 1) So to specify a desired precision one may use something like: > ...INTEGER, PARAMETER :: EP = SELECTED_REAL_KIND(35) > ...REAL (KIND = EP) :: X, Y > to declare the variables X and Y to be REAL floating-point variables > with 35 decimal digits accuracy. > But such desired precision may not be available on a particular m/c. > Would such declaration result in a compiler error ?? > Or would the compiler (g95) simply ignore it and assign whatever > (lower) precision available ?? The result is a scalar of type default integer. The result has a value equal to a value of the kind parameter of a real data type with decimal precision, as returned by the function PRECISION, of at least p digits and a decimal exponent range, as returned by the function RANGE, of at least r. If no such kind type parameter is available on the processor, the result is as follows: -1 if the precision is not available -2 if the exponent range is not available -3 if neither is available If more than one kind type parameter value meets the criteria, the value returned is the one with the smallest decimal precision. It's the programmer's responsibility to build in the appropriate action on the call returning result<0. > 2) On the other hand, the intrinsic PRECISION(X) returns the property > (i.e.; precision) of X. > But this is after the fact! > One still has to know the highest precision available for consistency > and portability. > Correct ?? > It might be possible to combine SELECTED_REAL_KIND() with PRECISION(). .... That's the idea behind the intrinsics of being able to programmatically determine whether or not a given level of precision is or is not available. As implemented, it is essentially presumed that the programmer knows whether a given precision is adequate for the task and the information returned allows one to determine that for any compliant compiler. It isn't the design to probe the hardware for the highest possible supported native type which seemed to be the way the question was worded in your posting. IIUC, of course, there's nothing that says the supported SELECTED_REAL_KIND isn't a software emulation, not processor hardware-implemented. I don't recall if the module I'm thinking of was one of Richard M's or not; certainly he has provided much thoughtful input on the subject along w/ many of the other notable regulars in clf. --
From: steve on 9 Aug 2010 15:42
On Aug 9, 12:19 pm, monir <mon...(a)rogers.com> wrote: > On Aug 9, 2:00 pm, dpb <n...(a)non.net> wrote: > > > Those are the uses of SELECTED_REAL_KIND() and PRECISION() > > > There have been posted modules on clf previously for suggestions of > > generic usage/determinations... > > 1) So to specify a desired precision one may use something like: > ...INTEGER, PARAMETER :: EP = SELECTED_REAL_KIND(35) > ...REAL (KIND = EP) :: X, Y > to declare the variables X and Y to be REAL floating-point variables > with 35 decimal digits accuracy. > But such desired precision may not be available on a particular m/c. > Would such declaration result in a compiler error ?? > Or would the compiler (g95) simply ignore it and assign whatever > (lower) precision available ?? These questions are answered in the standard, and I suspect these questions are answered in your compiler documentation. Heck, a 5 line program will give you the answer. program duh do i = 1, 35 print *, i, selected_real_kind(p=i) end do end program duh -- steve |