Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

quadruple precision - Set the default real type to an 16 byte in c program

With gfortran compiler, the flag -fdefault-real-16 helps to set the default real type to an 16 byte wide type. for example

program qp_test
implicit none 
      double precision  :: a    
      a  = 123456789012345678.123456789012345678
      write(*,'(a,g41.36)') 'my a    = ',a
      write(*,'(a)')        'exact a = 123456789012345678.123456789012345678'
end program 

When is complied as

gfortran qp_test.f90

The result is looks like

my a    = 123456790519087104.000000000000000000    
exact a = 123456789012345678.123456789012345678 

And when is compiled as

gfortran qp_test.f90 -fdefault-real-16

The result is looks like

my a    = 123456789012345678.123456789012345677    
exact a = 123456789012345678.123456789012345678 

So, I tried to do the same with c program

#include<stdio.h>
#include<string.h>
int main() {
   double a;
   a  = 123456789012345678.123456789012345678;           
   printf("my a    = %36.18f
", a);
   printf("exact a = 123456789012345678.123456789012345678
");
   return 0;
}

The problem is : Even the c program is compiled with -m64 flag, such as

gcc qp_test.c -o qp_test_c -m64

It gives the same result

my a    = 123456789012345680.000000000000000000
exact a = 123456789012345678.123456789012345678

The question is : Is there some how to tell gcc to compile "double" as "long double"?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...