🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#1
From: Barry G. Adams
Date: Wed, 18 Mar 1998 00:00
45 lines
2388 bytes


Albert Lo wrote:

> I think your bug means the following output for "expected" zero.
> The reason should be same to that we never compare floating point number
> with zero.
> It depends on the precision of IEEE format of floating point number.
> -1
> -0.9
> -0.8
> -0.7
> -0.6
> -0.5
> -0.4
> -0.3
> -0.2
> -0.1
> -1.38778e-016
> 0.1
> 0.2
> 0.3
> 0.4
> 0.5
> 0.6
> 0.7
> 0.8
> 0.9
> 1

There is no bug here. The fraction 0.1 does not have an exact floating point binary
representation. Therefore when you start at -0.1 and continually add 0.1 then at
each step there is a small round-off error. The default conversion in java is to display
floating point numbers with 6 significant figures. For this display accuracy the numbers
-1 to -0.1 appear to be reproduced exactly, but the next step produces the entry that is
not zero to 6 significant figures. Try it with float and there will be other differences.

So it's not a bug, just a property of floating point arithemtic.

Barry Adams
(barry@bethel.cs.laurentian.ca)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Technical Details
Message-ID: <350FFA6F.EDF71987@bethel.cs.laurentian.ca>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <34fed1be.3599015@news.uni-c.dk> <350E8AC4.AC8A6ACA@netvigator.com>

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: 109fba,982e935b1f8b3f3e
X-Google-Attributes: gid109fba,public
X-Google-Thread: f5d71,982e935b1f8b3f3e
X-Google-Attributes: gidf5d71,public
X-Google-Thread: 10a146,982e935b1f8b3f3e
X-Google-Attributes: gid10a146,public
X-Google-Thread: 109b8e,982e935b1f8b3f3e
X-Google-Attributes: gid109b8e,public
From: "Barry G. Adams" <barry@bethel.cs.laurentian.ca>
Subject: Re: Error in Microsoft Visual C++ v5, Borland C++ v5.01, JDK v1.1.5 when using "double" as type.
Date: 1998/03/18
Message-ID: <350FFA6F.EDF71987@bethel.cs.laurentian.ca>
X-Deja-AN: 335319881
Content-Transfer-Encoding: 7bit
References: <34fed1be.3599015@news.uni-c.dk> <350E8AC4.AC8A6ACA@netvigator.com>
Mime-Version: 1.0
Reply-To: barry@bethel.cs.laurentian.ca
Content-Type: text/plain; charset=us-ascii
Organization: Laurentian University
Newsgroups: microsoft.public.USASalesInfo.Developer.VisualC++,comp.lang.java.programmer,comp.lang.java,comp.lang.c++,borland.public.cpp.language