|
|||
|
In article <juh1p3$pf7$1@speranza.aioe.org>, dpb <none@non.net> writes:
> > I have some code in DOUBLE PRECISION which, however, has real input and > > output values. The input values are converted to internal variables via > > DBLE and the results are converted to the output values via REAL. > > > > Suppose an input value X is some number which has no exact > > floating-point represenation, e.g. 2.63. What should I expect the value > > DBLE(X) to be, tested by PRINT* during the code? Should I expect > > 2.63000000000000000 or 2.63<"random" digits>? > > Functions that cause conversion of one data type to another type > have the same effect as the implied conversion in assignment > statements. Right. Considering this, is there any reason to use them, except to force the conversion to be done just once rather than many times if they are used in more than one expression which needs conversion? (Now, I'm discussing only the values, not the difference between DBLE(X)/DBLE(Y) and DBLE(X/Y).) > So, you shouldn't expect some magic zero (decimal) extension just > because of the explicit cast. OK. > 0 (binary digits) extension doesn't translate to zero in decimal in > floating point representation. OK. > So, the answer is the later (but they're not "random" (altho I presume > that the quotes mean you understand that, maybe, I'm not sure???). Right, that's what the quotes mean! Presumably, once the value is stored in a REAL variable, the information regarding it's "real" value is lost, due to the finite precision. Suppose I have something like 2.63 as a character string. Is there a way to get this into a DOUBLE PRECISION variable with value 2.6300000000? (Yes, there's probably a better solution to my problem; I'm just asking this out of curiosity.) |
|
|
||||
|
||||
|
|
|
|||
|
On 7/22/2012 9:21 AM, Phillip Helbig---undress to reply wrote:
> In article<juh1p3$pf7$1@speranza.aioe.org>, dpb<none@non.net> writes: .... >> Functions that cause conversion of one data type to another type >> have the same effect as the implied conversion in assignment >> statements. > > Right. Considering this, is there any reason to use them, except to > force the conversion to be done just once rather than many times if they > are used in more than one expression which needs conversion? (Now, I'm > discussing only the values, not the difference between DBLE(X)/DBLE(Y) > and DBLE(X/Y).) I see no advantage, no. One may as well write Y=X ! where Y is the DP; X the SP variable as Y=DBLE(X) and just use Y from then on. Altho it probably can't be be assured, I'd expect compilers to be pretty smart in not doing unnecessary conversions in localized areas of code even if written explicitly during optimization. .... > Suppose I have something like 2.63 as a character string. Is there a > way to get this into a DOUBLE PRECISION variable with value > 2.6300000000? (Yes, there's probably a better solution to my problem; > I'm just asking this out of curiosity.) Sure...internal READ into a DP variable will do the conversion just as it would from external i/o The better solution would probably be to go ahead and do the above--convert the input variables to DP and let the i/o rtl take care of it for you transparently. I'd say today any concern about the extra memory required of DP over single that may have prompted such when the code was written has pretty much vanished unless it's either a huge set of data or a very restricted environment either of which probably deserves other considerations anyway. -- |
|
|||
|
On Monday, 23 July 2012 00:21:47 UTC+10, Phillip Helbig---undress to reply wrote:
> Suppose I have something like 2.63 as a character string. Is there a > way to get this into a DOUBLE PRECISION variable with value > 2.6300000000? Use an internal READ. |
|
|||
|
On Jul 23, 12:31*am, dpb <n...@non.net> wrote:
> On 7/22/2012 9:21 AM, Phillip Helbig---undress to reply wrote:> In article<juh1p3$pf...@speranza.aioe.org>, dpb<n...@non.net> *writes: > > ... > > >> Functions that cause conversion of one data type to another type > >> have the same effect as the implied conversion in assignment > >> statements. > > > Right. *Considering this, is there any reason to use them, except to > > force the conversion to be done just once rather than many times if they > > are used in more than one expression which needs conversion? *(Now, I'm > > discussing only the values, not the difference between DBLE(X)/DBLE(Y) > > and DBLE(X/Y).) > > I see no advantage, no. *One may as well write > > Y=X *! where Y is the DP; X the SP variable > > as > > Y=DBLE(X) > > and just use Y from then on. Indeed. There are few reasons for using DBLE : one would be to transform an argument to double precision when passing it to a procedure. Another could be to transform a REAL variable to double precision, again in an expression. Usually, however, some operand in an expression is already double precision, in which case, DBLE may not be needed. |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|