🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: microsoft.public.USASalesInfo.Developer.VisualC++
Article #5

Re: Error in Microsoft Visual C++ v5, Borland C++ v5.01, JDK v1.1.5 when using "double" as type.

#5
From: Pete Becker
Date: Mon, 02 Mar 1998 00:00
33 lines
1973 bytes
Azri Nielsen-Ferreira wrote:
> 
> There seems to be an error when using a the type "double" in C++ or
> Java. I have tested the program on PowerBuilder and Lotus Notes and
> both have the same error as Borland C++ v5.01, Microsoft Visual C++
> v5. I have tried the program with JDK v1.1.5 and Borland JBuilder too
> and they also have the same problem.
> 
> Look at the following program and test it with your compiler
> 
> C++ example:
> 
> #include <iostream.h>
> void main(void)
> {
>         for (double d=-1.0;d<1.0;)
>         {
>                 cout << d << endl;
>                 d=d+0.1;
>         }
> }
> 

0.1 does not have an exact representation as a binary floating point
value, so the actual value that the compiler uses is slightly less than
0.1, which results in an extra trip through the loop. It's really the
same problem as in this infinite loop:

for( int i = 0; i < 10; i += 1/3 )
	cout << i << endl;

	-- Pete
Technical Details
Message-ID: <34FB3C8A.D24983EF@acm.org>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <34fed1be.3599015@news.uni-c.dk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f8d38,982e935b1f8b3f3e
X-Google-Attributes: gidf8d38,public
X-Google-Thread: f5d71,982e935b1f8b3f3e
X-Google-Attributes: gidf5d71,public
X-Google-Thread: 109fba,982e935b1f8b3f3e
X-Google-Attributes: gid109fba,public
X-Google-Thread: 109b8e,982e935b1f8b3f3e
X-Google-Attributes: gid109b8e,public
X-Google-Thread: 10a146,982e935b1f8b3f3e
X-Google-Attributes: gid10a146,public
From: Pete Becker <petebecker@acm.org>
Subject: Re: Error in Microsoft Visual C++ v5, Borland C++ v5.01, JDK v1.1.5 when using "double" as type.
Date: 1998/03/02
Message-ID: <34FB3C8A.D24983EF@acm.org>
X-Deja-AN: 330178301
Content-Transfer-Encoding: 7bit
References: <34fed1be.3599015@news.uni-c.dk>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Organization: MediaOne -=- Northeast Region
Newsgroups: microsoft.public.USASalesInfo.Developer.VisualC++,comp.lang.java.programmer,comp.lang.java,comp.lang.c++,borland.public.cpp.language