Mail Archives: djgpp/2001/04/30/12:15:14
Rafal Maj <maj_rafal AT poczta DOT onet DOT pl> wrote:
> Hi,
> following code :
> long double r =
> 3.1415012345678901111112222233333444445555666677777888899999000012345;
> cerr << setprecision(999) << r;
> displays in cerr only : 3.1415012345678903
> How to display (or write to file) long double with full precision using
> iostream ? Or does long double hold only 16 digits of my variable ?
Long double holds more than 16 digits, but your way of initializing doesn't
give it more than 16, I think. The problem is that your constant isn't
flagged as a long double, and thus may be interpreted as a double.
Try:
long double r = 3.1415012345678901111112222233333L;
There's no good reason to provide that many (or even more) digits ---
even long double stores only around 20 (LDBL_EPSILON is 1.08e-19,
roughly). The "L" suffix is important, because of this (taken from the
C99 standard draft):
[#4] An unsuffixed floating constant has type double. If
suffixed by the letter f or F, it has type float. If
suffixed by the letter l or L, it has type long double.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -