delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/05/00:10:21

From: nxk3 AT dante DOT student DOT cwru DOT edu (Natarajan Krishnaswami)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Floating Point???
Date: 5 Mar 1997 04:15:58 GMT
Organization: Case Western Reserve University, Cleveland OH (USA)
Lines: 24
Message-ID: <slrn5hpsq2.6nd.nxk3@dante.student.cwru.edu>
References: <4b5_9703051119 AT softtech DOT brisnet DOT org DOT au> <5fin95$f8 AT news DOT ox DOT ac DOT uk>
Reply-To: nxk3 AT dante DOT cwru DOT edu
NNTP-Posting-Host: dante.student.cwru.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On 5 Mar 1997 02:54:29 GMT, George Foot <gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk> wrote:
> Ron T Lewis (ron DOT t DOT lewis AT softtech DOT brisnet DOT org DOT au) wrote:
> 
> : int main()
> : {
> : float a;
> : a=4.00/5.00;
> : printf("float = %.12f\n",a);
> : return(1);
> : }
> : Ans = 0.800000011921
> 
> : The correct answer should be 0.800000000000 but he gets these extroneous 
> : numbers tacked on the end???
> 
> `float' numbers aren't that accurate; use `double's instead. Replace `float'
> with `double' throughout, and change `%.12f' to `%.12lf', and you should get
> the right answer.

That should be "%Lf" for long doubles, and "%f" for floats and
doubles.


N.

- Raw text -


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