www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/05/02/20:39:09

From: Jason Green <news AT jgreen4 DOT fsnet DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Iostream question
Date: Wed, 02 May 2001 23:46:16 +0100
Lines: 49
Message-ID: <ca21ft0rljn2p14j254ufh52kliep94uem@4ax.com>
References: <9cjlhq$3vf$1 AT info DOT cyf-kr DOT edu DOT pl> <9cjp4v$nps$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE>
NNTP-Posting-Host: modem-154.xenon.dialup.pol.co.uk
Mime-Version: 1.0
X-Trace: newsg2.svr.pol.co.uk 988843556 6150 62.136.45.154 (2 May 2001 22:45:56 GMT)
NNTP-Posting-Date: 2 May 2001 22:45:56 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Newsreader: Forte Agent 1.7/32.534
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de> wrote:

> Rafal Maj <maj_rafal AT poczta DOT onet DOT pl> wrote:

> > following code :
> >   long double r =
> > 3.1415012345678901111112222233333444445555666677777888899999000012345;
> >   cerr << setprecision(999) << r;
> > displays in cerr only : 3.1415012345678903

Hmmm, interesting bug.

#include <iostream>
#include <iomanip>

int main()
{
  long double r =

3.1415012345678901111112222233333444445555666677777888899999000012345;

  int i;
	
  for (i=1; i<2000; i++)
    cerr << i << " " << setprecision(i) << r << endl;
}

> > How to display (or write to file) long double with full precision using
> > iostream ? 

Try setprecision(998) or setprecision(1000)  :-)

> Or does long double hold only 16 digits of my variable ?

It will hold more than that, but not necessarily the exact value that you
assign it.

> Try:
> 
>   long double r = 3.1415012345678901111112222233333L;

>        [#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.

Well if that's what the standard says... ;-).  FWIW, adding the L suffix
seems to make no difference.

Roll on gcc 3.0.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019