- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Hi,
I'm wondering, how to get exact same real*8 number from real*4 numbers. Example:
real*4 x4
real*8 x8,y8
x4=2.7
x8=dble(x4)
y8=2.7d0
write(*,*) x4, x8, y8
end
gives:
2.700000 2.70000004768372 2.70000000000000
So,shouldnt dble() initialize the rest of the mantissa to zero to have x8=x4 in common sense (y8 shows, this number exist :)
Cite from dble(a) documentaton in CVF:
"If a is of type integer or real, the result has as much precision of the significant part of a as a double precision value can contain."
Any work-around, which stands optimization ?
Thanks
Martin
I'm wondering, how to get exact same real*8 number from real*4 numbers. Example:
real*4 x4
real*8 x8,y8
x4=2.7
x8=dble(x4)
y8=2.7d0
write(*,*) x4, x8, y8
end
gives:
2.700000 2.70000004768372 2.70000000000000
So,shouldnt dble() initialize the rest of the mantissa to zero to have x8=x4 in common sense (y8 shows, this number exist :)
Cite from dble(a) documentaton in CVF:
"If a is of type integer or real, the result has as much precision of the significant part of a as a double precision value can contain."
Any work-around, which stands optimization ?
Thanks
Martin
Link kopiert
3 Antworten
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
It DOES set the rest of the mantissa to zero - binary zero! That's not the same as decimal zero! (Look for an article in our upcoming newsletter that discusses this issue in general - it will be available to registered users only.)
Once you have assigned a REAL*4 value, there's no way to "create" the extra precision that a REAL*8 value would have had.
Steve
Once you have assigned a REAL*4 value, there's no way to "create" the extra precision that a REAL*8 value would have had.
Steve
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Thanks for your prompt answer. But ...
The consequence of this unpredictable 'binary' addon: no local change to double precision, e.g. in critical functions wich handle small differences of large numbers. I have constructed a small example, where double precision results in larger error than staying in single precision.
You mentioned a newsletter article, I guess not out yet. Any chance to get an idea how to get rid of that problem ? (I'm registrated, email ok)
Martin
The consequence of this unpredictable 'binary' addon: no local change to double precision, e.g. in critical functions wich handle small differences of large numbers. I have constructed a small example, where double precision results in larger error than staying in single precision.
You mentioned a newsletter article, I guess not out yet. Any chance to get an idea how to get rid of that problem ? (I'm registrated, email ok)
Martin
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
It's not unpredictable - it's VERY predictable. DBLE will zero-extend the fraction from single-precision to double-precision with binary zeroes. You evidently want decimal zeroes added - that's not the way it works. (And if you had assigned x8=x4, you'd see the same thing.)
My first suggestion would be to use double precision throughout your application, being sure to use the D0 form of constants. You could also do a conversion as follows:
My first suggestion would be to use double precision throughout your application, being sure to use the D0 form of constants. You could also do a conversion as follows:
character*13 buff
...
write (buff,'(E13.6)') x4
read (buff,'(E13.6)') x8
That should extend the value with decimal zeroes.
I expect the newsletter to be out in a week or so. Watch your e-mail for the pointer.
Steve

Antworten
Themen-Optionen
- RSS-Feed abonnieren
- Thema als neu kennzeichnen
- Thema als gelesen kennzeichnen
- Diesen Thema für aktuellen Benutzer floaten
- Lesezeichen
- Abonnieren
- Drucker-Anzeigeseite