🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #15101

Re: Question about mathemathics.

#15101
From: Steve Schafer (TeamB)
Date: Thu, 08 Jul 1999 00:00
25 lines
1290 bytes
On Thu, 8 Jul 1999 15:32:48 +0300, "Alexander Stanev"
<a_stanev@iname.com> wrote:

>What is wrong with Java mathematics?

Nothing.

>I wrote:
>double x = 1.255;
>double y = 0;
>y = x + 0.005;
>As a rezult I receive y = 1.2599999999999998.
>Why?

In general, floating-point representations cannot express decimal
fractions exactly. For the same reason you cannot express 1/3 in a
finite number of decimal digits, you cannot express 1/10 in a finite
number of binary digits.

Therefore, all floating-point values are _approximations_. You must
_always_ deal with floating-point values with that in mind. This is
not just in Java; it is true in every programming language that uses
floating-point representations.
 
-Steve
Technical Details
Message-ID: <3793cecc.45267452@90.0.0.40>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7m25jr$heu6@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,f8b18e8225438be9
X-Google-Attributes: gidf74b3,public
From: pandeng@telepath.com (Steve Schafer (TeamB))
Subject: Re: Question about mathemathics.
Date: 1999/07/08
Message-ID: <3793cecc.45267452@90.0.0.40>
X-Deja-AN: 498702929
Content-Transfer-Encoding: 7bit
References: <7m25jr$heu6@forums.borland.com>
Content-Type: text/plain; charset=us-ascii
Organization: TeamB
Mime-Version: 1.0
Reply-To: pandeng@telepath.com
Newsgroups: borland.public.jbuilder.java.language