This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: problems with long double data type...


On Tue, Nov 12, 2002 at 02:45:42PM +0000, Gabriel Andres Goenaga Jimenez wrote:
> I have working with long double data type.  When I try to print the content 
> of variables with printf or fprintf the data are printed like double type 
> (in the 1e-307 to 1e+307).  I'm compiling my program with gcc in Linux 
> redhat 7.3, my cpu is a Pentium II.  Anybody know what is the problem.  I 
> think may be the compiler, because when I try to the same in borland c++ for 
> dos it work well, other posibilitie is that the function prinft cannot work 
> with this data type, but I could'nt find a solution.
> 
> Please, help me.
> 
Hi,
I don't know if stdio.h in RH7.3 is suitable for printing long double but
installing GSL from scratch would require you to run configure script that
checks this. In the meanwhile, assuming you need precision rather than large
exponents, you might try something like this:

#include <stdio.h>

int main(){
	long double pi;
	pi = 3.14159265358979323; /* this is outside double precision limit */
	printf("%24.18f\n", (double) pi);
	return 0;
}

this will print correct value of pi to double precision. If you need to print
results to long double precision, you most likely need to recompile your C
library. If you need large exponents then the solution above will overflow (or
underflow) so you need to check and rescale your numbers before casting them
into double.
BTW, this question looks more appropiate for a C or GCC discussion group.
cheers,

ato


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]