From: Tobias Burnus on 10 Jun 2010 08:48 On 06/10/2010 01:45 PM, deltaquattro wrote: >> In Fortran, the default LOGICAL is the same size as default REAL. >> You may have a smaller size available, though. > > Wow! Really? I didn't know....it does seems a bit strange to me, > though. Wouldn't a single bit be sufficient for LOGICAL? In principle, a single bit is enough - and often compiler only check a single bit for "IF (logical_var)" [typically either the first or last bit]. But extracting a certain single bit out of, e.g., a 32bit variable of 32 bits takes longer than having an array of 32 32bit logicals an checking the Boolean status of one array element. Usually, the logical values play not a major role in most programs - neither in terms of memory size nor in performance - and thus sticking to the default-kind logical is sufficient. My compiler has on the x86-64 platform logicals of the size 1, 2, 4, 8, and 16 bytes - and with the bit operations on integers, one can create also 1-bit 'logicals'. >> Note that 9e99 is too big >> for the single precision REAL on most systems. I believe that >> before IEEE, this was the usual solution. Likely still even with >> IEEE, as long as non-IEEE machines are around. > > No problem, as said before I made a mistake, it's really a DOUBLE > PRECISION variable. I think using 'var = HUGE(var)' can be more readable than 9.0e99_r8 and is slightly less arbitrary. > IF (x/=x) THEN > ! It's a NaN, do something here > END IF > could fail on some compilers. Of course, I may be wrong. Probably, though I think the more common issue are compiler options (assume no NaN/INF) and not that the compiler always optimizes such a test away. > Thanks! I think I'll go for 9.9999e99, but just in case I decide to > switch to NaN, could you please suggest a good way to fill the cell > with a NaN? Something like > > A=0 > arr(i,j)=A/0 > > should work if I'm not compiling with debugging options on, I think. I think it does - though with F2003's IEEE module you can also use: USE IEEE_ARITHMETIC .... array(:) = IEEE_value (array, IEEE_QUIET_NAN) Assuming that your compiler supports this F2003 intrinsic module. Tobias
From: deltaquattro on 10 Jun 2010 08:49 On 10 Giu, 05:36, robert.corb...(a)oracle.com wrote: > On Jun 9, 2:41 pm, Gib Bogle <g.bo...(a)auckland.no.spam.ac.nz> wrote: > > > glen herrmannsfeldt wrote: > > > I don't recommend the LOGICAL variable method, unless it is > > > necessary to have all REAL values legal. If you need portability > > > to older compilers, you could do conditional compilation on a > > > test for NaN or 9.9999e30 (fits in single precision on most > > > machines), or 9.9999e99 (in double precision on many machines). > > > Is 9.9999e30 exactly representable? Anyway, why not use 1.0e30, which > > definitely is? I like your idea of incrementally modifying true values that hit > > the "missing point" value. [..] > > Bob Corbett Hi Bob, so this means that I wouldn't be able to test for equivalence against 9.9999e30 or 1.0E30? Alas, I forgot one shouldn't test for equivalence with floating point numbers... Best Sergio Rossi
From: deltaquattro on 10 Jun 2010 08:55 On 10 Giu, 06:14, wclod...(a)lost-alamos.pet (William Clodius) wrote: > deltaquattro <deltaquat...(a)gmail.com> wrote: > > Hi, > > > this is really more of a "numerical computing" question, so I cross- > > post to sci.math.num.analysis too. I decided to post on > > comp.lang.fortran, anyway, because here is full of computational > > scientists and anyway there are some sides of the issue specifically > > related to Fortran language. > > > The problem is this: I am modifying a legacy code, and I need to > > compute some REAL values which I then store in large arrays. Sometimes > > it's impossible to compute these values: for example, think of > > interpolating a table to a given abscissa, it may happen that the > > abscissa falls outside the curve boundaries. I have code which checks > > for this possibility, and if this happens the interpolation is not > > performed. However, now I must "store" somewhere the information that > > interpolation was not possible for that array element, and inform the > > user of it. Since the values can be either positive or negative, I > > cannot use tricks like initializing the array element to a negative > > values. > > <snip> > > Is there more than one way the interpolation can fail and shoult the > user be aware of these distinctions? If so then I suggest a > corresponding flag array of chararacters of length 1. Define character > parameters of the same length, e.g., TOO_LOW, TOO_HIGH, VALID, ... with > distinct values and assign to the duplicate array as the proper state is > recognized. Consider initializing the character array element to a > special distinct value, say UNPROCESSED. Also consider assignining an > NaN to invalid elements so that if you fail to to use the flag array to > determine the processing flow the failure will be obvious. > > -- > Bill Clodius > los the lost and net the pet to email Hi, Bill, yours is a variation on point 1 (define a corresponding LOGICAL array for each REAL(r8) array), isn't it? So you suggest to define an extra array for each of my arrays, which works as a flag array. I don't understand exactly how to form the array. You talk about strings of lenght 1, but TOO_LOW, TOO_HIGH, etc., UNPROCESSED are not of length 1 and they are of different length. I guess the array should be of type CHARACTER(LEN=MAXL) where MAXL is the length of the longest string. Am I right? Thanks Sergio Rossi
From: FX on 10 Jun 2010 09:21 > Let's say I choose this solution: what I missing here is, how do I > fill an array elements with a NaN? Will this be portable? Not portable, but if your real and double precision types follow IEEE layout, you can use: real function nan () nan = transfer(z'FFC00000',nan) end function nan double precision function nand () nand = transfer(z'FFF8000000000000',nand) end function nand -- FX
From: Les Neilson on 10 Jun 2010 09:48
"deltaquattro" <deltaquattro(a)gmail.com> wrote in message news:7707ce5a-1fbe-4d12-9bae-ecdb94ef2ce8(a)s9g2000yqd.googlegroups.com... > On 10 Giu, 06:14, wclod...(a)lost-alamos.pet (William Clodius) wrote: >> Is there more than one way the interpolation can fail and shoult the >> user be aware of these distinctions? If so then I suggest a >> corresponding flag array of chararacters of length 1. Define character >> parameters of the same length, e.g., TOO_LOW, TOO_HIGH, VALID, ... with >> distinct values and assign to the duplicate array as the proper state is >> recognized. Consider initializing the character array element to a >> special distinct value, say UNPROCESSED. Also consider assignining an >> NaN to invalid elements so that if you fail to to use the flag array to >> determine the processing flow the failure will be obvious. >> >> -- >> Bill Clodius >> los the lost and net the pet to email > > Hi, Bill, > > yours is a variation on point 1 (define a corresponding LOGICAL array > for each REAL(r8) array), isn't it? So you suggest to define an extra > array for each of my arrays, which works as a flag array. I don't > understand exactly how to form the array. You talk about strings of > lenght 1, but TOO_LOW, TOO_HIGH, etc., UNPROCESSED are not of length 1 > and they are of different length. I guess the array should be of type > CHARACTER(LEN=MAXL) where MAXL is the length of the longest string. Am > I right? Thanks > > Sergio Rossi If I understand Bill correctly you would have something like real(of_the_right_kind) HIGH_VALUE :: parameter = whatever high value is appropriate real(of_the_right_kind) LOW_VALUE :: parameter = whatever low value is appropriate character, TOO_LOW :: parameter = 'L' ! character string of length one character, TOO_HIGH :: parameter = 'H' character, UNPROCESSED :: parameter = 'U' character, JUST_RIGHT :: parameter = 'J' character flags(size_of_matching_array) ! Initialise flags flags = UNPROCESSED ! Process the data array ! and set the flags array if necessary if (data_array(i) >= HIGH_VALUE) flags(i) = TOO_HIGH if (data_array(i) <= LOW_VALUE) flags(i) = TOO_LOW if (data_array(i) > LOW_VALUE .and. data_array(i) < HIGH_VALUE) flags(i) = JUST_RIGHT etc Les |