public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
* problems with long double data type...
@ 2002-11-12  9:04 Gabriel Andres Goenaga Jimenez
  2002-11-12  9:08 ` Atakan Gurkan
  0 siblings, 1 reply; 4+ messages in thread
From: Gabriel Andres Goenaga Jimenez @ 2002-11-12  9:04 UTC (permalink / raw)
  To: gsl-discuss

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.

Gabriel Goenaga Jimenez
Graduate Student
Physics Departmente
University or Puerto Rico





_________________________________________________________________
MSN Fotos: la forma más fácil de compartir e imprimir fotos. 
http://photos.msn.es/support/worldwide.aspx

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

* Re: problems with long double data type...
  2002-11-12  9:04 problems with long double data type Gabriel Andres Goenaga Jimenez
@ 2002-11-12  9:08 ` Atakan Gurkan
  2002-11-12 10:08   ` Atakan Gurkan
  0 siblings, 1 reply; 4+ messages in thread
From: Atakan Gurkan @ 2002-11-12  9:08 UTC (permalink / raw)
  To: gsl-discuss

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

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

* Re: problems with long double data type...
  2002-11-12  9:08 ` Atakan Gurkan
@ 2002-11-12 10:08   ` Atakan Gurkan
  0 siblings, 0 replies; 4+ messages in thread
From: Atakan Gurkan @ 2002-11-12 10:08 UTC (permalink / raw)
  To: gsl-discuss

On Tue, Nov 12, 2002 at 11:02:29AM -0600, Atakan Gurkan wrote:
> 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 */
ooops I made a mistake. This should read:
pi = 3.14159265358979323L;
otherwise compiler will truncate it during compilation :(. It doesn't change the
idea i was trying to illustrate but, what I have written was not what I meant.
> 	printf("%24.18f\n", (double) pi);
> 	return 0;

ato

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

* problems with long double data type...
@ 2002-11-12  9:05 Trevor Blackwell
  0 siblings, 0 replies; 4+ messages in thread
From: Trevor Blackwell @ 2002-11-12  9:05 UTC (permalink / raw)
  To: Gabriel Andres Goenaga Jimenez; +Cc: gsl-discuss


if you have:

  long double x;

use:

  printf("%Lg",x)

(or %Lf or %Le, as you prefer.) "man 3 printf" has the full details

-- 
Trevor Blackwell      tlb@anybots.com       (650) 776-7870

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

end of thread, other threads:[~2002-11-12 17:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-12  9:04 problems with long double data type Gabriel Andres Goenaga Jimenez
2002-11-12  9:08 ` Atakan Gurkan
2002-11-12 10:08   ` Atakan Gurkan
2002-11-12  9:05 Trevor Blackwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).