Mail Archives: djgpp/1997/08/18/20:35:35
From: | mschulter AT DOT value DOT net (M. Schulter)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | pb with long double
|
Date: | 15 Aug 1997 00:49:32 GMT
|
Organization: | Value Net Internetwork Services Inc.
|
Lines: | 72
|
Message-ID: | <5t092s$hsi$1@vnetnews.value.net>
|
NNTP-Posting-Host: | value.net
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
> I am a french student and I have little problem with GCC
> Here is my program :
> #include <math.h>
> main()
> {
> long double a;
> a=PI;
> printf("%22.20Lf",a);
> }
> The result is 3.14159265358979311600
> wrong
> There is only 15 good digits instead of 19
> ( PI is defined with more than 20 digits im math.h )
Hi, there. Here's a program which _may_ illustrate the problem and a
possible solution by returning the desired value with long double
precision:
#include <stdio.h>
#include <math.h>
#define L_PI 3.14159265358979323846L
int main(void)
{
long double a;
a=L_PI;
printf("%22.20Lf",a);
return(0);
}
At least with the outdated GCC 2.7.2 (DJGPP 2.00) that I'm regrettably
still using <grin>. it seems that a long double quantity must be
followed by the designator 'L' to be treated as a long double. When I
define my own L_PI as 3.14159...846L, running the revised program in
Emacs gives the result:
3.14159265358979323851
This result is correct to the first 19 digits, about what I would
expect from a long double.
Here's another example, this time focusing on magnitude:
#include <stdio.h>
#include <math.h>
int main(void)
{
long double a;
a=3.11e4000L;
printf("%22.20Le",a);
return(0);
}
Note that this works to around 19-digit precision, but if I rewrite
the assignment to:
a=3.11e4000;
without that 'L', then the output from GCC 2.7.2 is 'Inf' -- since the
limits of a double have been exceeded.
Most respectfully,
Margo Schulter
mschulter AT value DOT net
- Raw text -