|
Prev: What should MIN and MAX do when an argument is NaN ?
Next: Strange change of behaviour, executing daughter programs in Windows
From: Gerry Ford on 8 Apr 2008 23:42 A person is stipulated to make a selected_real_kind call with (12, 23) as arguments. I'm given to understand that 12 addresses the range while 23 the precision. What is he asking his compiler for here? I've been puzzling over this for the better part of a day, which began by running this program: print *, range(1), range(1.0), range(1.0d0) end This would count as the shortest useful program I have ever replicated. The output for my machine is, respectively, 9, 37 and 307. If a compiler knows that my answers to the range questions are as above, how will it decide what to do with (12,23)? -- "That this social order with its pauperism, famines, prisons, gallows, armies, and wars is necessary to society; that still greater disaster would ensue if this organization were destroyed; all this is said only by those who profit by this organization, while those who suffer from it - and they are ten times as numerous - think and say quite the contrary." ~~ Leo Tolstoy
From: FX on 9 Apr 2008 03:34 > A person is stipulated to make a selected_real_kind call with (12, 23) > as arguments. I'm given to understand that 12 addresses the range > while 23 the precision. What is he asking his compiler for here? Have you read the description of selected_real_kind in the standard or a textbook? I think it's really clear: --------------------------------- SELECTED_REAL_KIND ([P, R]) Description. Returns a value of the kind type parameter of a real type with decimal precision of at least P digits and a decimal exponent range of at least R. Class. Transformational function. Arguments. At least one argument shall be present. P (optional) shall be scalar and of type integer. R (optional) shall be scalar and of type integer. Result Characteristics. Default integer scalar. Result Value. If P or R is absent, the result value is the same as if it were present with the value zero. The result has a value equal to a value of the kind type parameter of a real 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, [or if no such kind type parameter is available on the processor, the result is −1 if the processor does not support a real type with a precision greater than or equal to P but does support a real type with an exponent range greater than or equal to R, −2 if the processor does not support a real type with an exponent range greater than or equal to R but does support a real type with a precision greater than or equal to P, −3 if the processor supports no real type with either of these properties, and −4 if the processor supports real types for each separately but not together.] If more than one kind type parameter value meets the criteria, the value returned is the one with the smallest decimal precision, unless there are several such values, in which case the smallest of these kind values is returned. --------------------------------- You can, in first reading, skip what I put inside square brackets, which describes the various error conditions of the routine. Now, after reading that, what do you not understand? > If a compiler knows that my answers to the range questions are as > above, how will it decide what to do with (12,23)? You gave us the range, but not the decimal precision. From the text above, you can see it is crucial to determine the result. -- FX
From: Gerry Ford on 9 Apr 2008 17:10 "FX" <coudert(a)alussinan.org> wrote in message news:fthri1$2cna$1(a)nef.ens.fr... >> A person is stipulated to make a selected_real_kind call with (12, 23) >> as arguments. I'm given to understand that 12 addresses the range >> while 23 the precision. What is he asking his compiler for here? > > Have you read the description of selected_real_kind in the standard or a > textbook? I think it's really clear: > > --------------------------------- > > SELECTED_REAL_KIND ([P, R]) > > Description. Returns a value of the kind type parameter of a real type > with decimal precision of at least P digits and a decimal exponent range > of at least R. > > Class. Transformational function. > > Arguments. At least one argument shall be present. > P (optional) shall be scalar and of type integer. > R (optional) shall be scalar and of type integer. This is remarkably readable for having come from the standard. One thing I didn't understand was what a compiler was to do if given one datum that would incline it to single precision and another that would incline it to double. It takes the one that is larger. > Result Characteristics. Default integer scalar. > > Result Value. If P or R is absent, the result value is the same as if it > were present with the value zero. The result has a value equal to a value > of the kind type parameter of a real 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, [or if > no such kind type parameter is available on the processor, the result is > ?1 if the processor does not support a real type with a precision greater > than or equal to P but does support a real type with an exponent range > greater than or equal to R, ?2 if the processor does not support a real > type with an exponent range greater than or equal to R but does support a > real type with a precision greater than or equal to P, ?3 if the > processor supports no real type with either of these properties, and ?4 > if the processor supports real types for each separately but not > together.] If more than one kind type parameter value meets the criteria, > the value returned is the one with the smallest decimal precision, unless > there are several such values, in which case the smallest of these kind > values is returned. > > --------------------------------- > > You can, in first reading, skip what I put inside square brackets, which > describes the various error conditions of the routine. > > Now, after reading that, what do you not understand? I was also able to find help in my current reference which is _Programming in Fortran 90_. I added the following to the shortest useful program: print *, "range", range(1), range(1.0), range(1.0d0) print *, "precision", precision(1.0), precision(1.0d0) print *, "tiny", tiny(1.0), tiny(1.0d0) print *, "huge", huge(1.0), huge(1.0d0) print *, "epsilon", epsilon(1.0), epsilon(1.0d0) end range 9 37 307 precision 6 15 tiny 1.175494E-38 2.225073858507E-0308 huge 3.402823E+38 1.797693134862E+0308 epsilon 1.192093E-07 2.220446049250E-16 >> If a compiler knows that my answers to the range questions are as >> above, how will it decide what to do with (12,23)? > > You gave us the range, but not the decimal precision. From the text > above, you can see it is crucial to determine the result. Did I not, in ignorance, already give 23? Since 23 is greater than 15, wouldn't a compiler be within its rights to hand me negative one? Furthermore, with constraints such as they are, wouldn't a compiler be justified in giving me the widest option for srk(1,1)? -- "That this social order with its pauperism, famines, prisons, gallows, armies, and wars is necessary to society; that still greater disaster would ensue if this organization were destroyed; all this is said only by those who profit by this organization, while those who suffer from it - and they are ten times as numerous - think and say quite the contrary." ~~ Leo Tolstoy
From: glen herrmannsfeldt on 9 Apr 2008 17:37 Gerry Ford wrote: (snip, regarding) >>SELECTED_REAL_KIND ([P, R]) > This is remarkably readable for having come from the standard. One thing I > didn't understand was what a compiler was to do if given one datum that > would incline it to single precision and another that would incline it to > double. It takes the one that is larger. In most cases that is probably right, but there may even be more than one choice. Consider VAX that has two different 64 bit floating point forms, trading exponent bits for significand bits. http://www.helsinki.fi/atk/unix/dec_manuals/df90au52/dfum045.htm It needs to return a KIND that satisfies both P and R. -- glen
From: Richard Maine on 9 Apr 2008 17:59
Gerry Ford <gerry(a)nowhere.ford> wrote: > "FX" <coudert(a)alussinan.org> wrote in message > news:fthri1$2cna$1(a)nef.ens.fr... > > Description. Returns a value of the kind type parameter of a real type > > with decimal precision of at least P digits and a decimal exponent range > > of at least R. > This is remarkably readable for having come from the standard. One thing I > didn't understand was what a compiler was to do if given one datum that > would incline it to single precision and another that would incline it to > double. It takes the one that is larger. Yep. That's what "...at least.. and...at least..." translates to. > >> If a compiler knows that my answers to the range questions are as > >> above, how will it decide what to do with (12,23)? > > > > You gave us the range, but not the decimal precision. From the text > > above, you can see it is crucial to determine the result. > Did I not, in ignorance, already give 23? Um. Yes. FX must have just been confused or something. That's exactly what the 23 would be in this context. > Since 23 is greater than 15, > wouldn't a compiler be within its rights to hand me negative one? No. Because the 23 is a range and thus has nothing to do with precision (which is the 15). This isn't exactly anything special - just ordinary positional argument usage. The first actual argument (12) goes with the first dummy argument (p), and the second actual argument (23) goes with the second dummy argument (r). The list of 2 arguments is *NOT* two values for the first argument. > Furthermore, with constraints such as they are, wouldn't a compiler be > justified in giving me the widest option for srk(1,1)? No. The specs are really all there if you just read all the way through them. Admitedly, this important part of the specs is sort of hidden behind all the fluff about what all the negative values mean(the part that FX put in brackets). One is tempted to stop reading when one hits that part. But if you actually plow on past it, you'll see (directly lifted from FX's posting) >> If more than one kind type parameter value meets the criteria, the >> value returned is the one with the smallest decimal precision, unless >> there are several such values, in which case the smallest of these >> kind values is returned. -- Richard Maine | Good judgement comes from experience; email: last name at domain . net | experience comes from bad judgement. domain: summertriangle | -- Mark Twain |