Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* g77 real size
@ 2002-10-16 19:25 Arkadiy Chapkis - Arc
  2002-10-17 11:24 ` Nelson Brito
  0 siblings, 1 reply; 3+ messages in thread
From: Arkadiy Chapkis - Arc @ 2002-10-16 19:25 UTC (permalink / raw)
  To: AXP-LIST

  Hello everyone.

  Sorry for the off-topic, I just wonder if there's a switch for g77 to make a
double precision number out of real fp number (not defined, used by default).
The piece of code

	a=1.
        b=a+1./1e12
        c=b-a
        write(*,*) c
        end

compiled with g77 cuts off everything after 8 digits left of point. Since
what's left are 8 zeros, the result is 0.
  I got the (almost) right result using Compaq fort with -real_size 64, but
don't know that there's something equivalent in g77.

  Thank you in advance,


                                      Arc C.
                                      achapkis@dls.net




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: g77 real size
@ 2002-10-16 21:21 Eugene Chu
  0 siblings, 0 replies; 3+ messages in thread
From: Eugene Chu @ 2002-10-16 21:21 UTC (permalink / raw)
  To: AXP-LIST, axp-list

Arkadiy Chapkis wrote:

>Sorry for the off-topic, I just wonder if there's a switch for g77 to
>make a double precision number out of real fp number (not defined, used
>by default).  The piece of code
>
>	a=1.
>        b=a+1./1e12
>        c=b-a
>        write(*,*) c
>        end
>
>compiled with g77 cuts off everything after 8 digits left of point.
>Since what's left are 8 zeros, the result is 0.
>
>I got the (almost) right result using Compaq fort with -real_size 64,
>but don't know that there's something equivalent in g77.

I wish to know the answer to this as well, but I think it's "no";
I did not see that option in g77.

I need the capability for something else, but if you're writing this
data out to a text file (or terminal), you should probably use an
explicit format specification with something like g16.7 for single
precision and g26.17 for double precision.  Otherwise, there is no
guarantee that you won't get mostly zeros even with double precision.

As you've already found out, as the magnitude of the value gets
smaller, the free-format output starts turning into zeros, effectively
losing precision.  This will happen using this output format even with
double presicion variables, which sort of defeats the purpose of using
double precision in the first place.

eyc




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: g77 real size
  2002-10-16 19:25 Arkadiy Chapkis - Arc
@ 2002-10-17 11:24 ` Nelson Brito
  0 siblings, 0 replies; 3+ messages in thread
From: Nelson Brito @ 2002-10-17 11:24 UTC (permalink / raw)
  To: axp-list

On Wed, 16 Oct 2002, Arkadiy Chapkis - Arc wrote:

>   Hello everyone.
> 
>   Sorry for the off-topic, I just wonder if there's a switch for g77 to make a
> double precision number out of real fp number (not defined, used by default).
> The piece of code

you need to declare the variables to be double precision
like real*8  declares "like" as a double precision real!


nelson

-- 
Nelson Brito
Faculdade de Ciencias | tel. +351226082841
Universidade do Porto | fax  +351226082959
R. Campo Alegre, 687  |
4169-007 Porto        |




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-10-17 10:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-16 21:21 g77 real size Eugene Chu
  -- strict thread matches above, loose matches on Subject: below --
2002-10-16 19:25 Arkadiy Chapkis - Arc
2002-10-17 11:24 ` Nelson Brito

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox