delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/03/07/22:10:55

From: Martin Ambuhl <mambuhl AT earthlink DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Problem with floats
Date: Sun, 07 Mar 1999 21:05:27 -0500
References: <36E32739 DOT E6E9AFA0 AT usa DOT net>
X-Posted-Path-Was: not-for-mail
X-Accept-Language: en
X-ELN-Date: 8 Mar 1999 02:05:12 GMT
X-ELN-Insert-Date: Sun Mar 7 18:15:01 1999
Organization: Nocturnal Aviation
Lines: 37
Mime-Version: 1.0
NNTP-Posting-Host: 1cust154.tnt14.nyc3.da.uu.net
Message-ID: <36E33067.55BC4857@earthlink.net>
X-Mailer: Mozilla 4.5 [en] (Win95; I)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Victor Senderov wrote:
> 
>  Hi,
> I wrote a test a program in order to see how djgpp will display a float
> and was puzzled by the following:
> 
> #include <iomanip.h>
> #include <iostream.h>
> int main()
> {
>  cout << setprecision(25);
>  double test = 37000.95000;
>  cout << test;
>  return 0;
> }
> 
> Output : 37000.94999999999708961695
> Can anybody explain why it outputs something so incorrect? 

How incorrect IS it?

The "correct" value was 37000.95000000000000
The printed value was 37000.94999999999709
The error was    -0.00000000000291
Which is a relative error of -7.86378e-15%

What in heaven's name did you expect?  Since when was 5 a power of 2?


>Also, I
> compiled this under other compiler and it worked ok -- the other
> compiler displayed 37000.95


-- 
Martin Ambuhl (mambuhl AT earthlink DOT net)
Note: mambuhl AT tiac DOT net will soon be inactive

- Raw text -


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