Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #20707

Re: Floating Point Representation (Question)

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail
NNTP-Posting-Date Wed, 26 Dec 2012 11:40:55 -0600
Date Wed, 26 Dec 2012 09:40:52 -0800
From Patricia Shanahan <pats@acm.org>
User-Agent Mozilla/5.0 (Windows NT 5.2; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0
MIME-Version 1.0
Newsgroups comp.lang.java.programmer
Subject Re: Floating Point Representation (Question)
References <floating-20121226170657@ram.dialup.fu-berlin.de>
In-Reply-To <floating-20121226170657@ram.dialup.fu-berlin.de>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 8bit
Message-ID <naWdndLP5J86q0bNnZ2dnUVZ_oydnZ2d@earthlink.com> (permalink)
Lines 36
X-Usenet-Provider http://www.giganews.com
NNTP-Posting-Host 70.230.205.210
X-Trace sv3-ojgguxgqpTrrHQLQWtH4uMe1bTpfExdfDClYS4/0MYfBCJs0jRYpSUSWiHEBfrNfq1/EMF9b+MRd0jl!Q+Apltbl1GI6vQhbs8mICy4mN6IIo4BKBQ3pVUMLyNAig1wOVNItMy/Hsj66xfRR3V4F6uwA+TFA!MFFbmoFSrC+stV7VPe8Cf58abHbQ/w8TOfp2RsvDV83r+co=
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 2432
Xref csiph.com comp.lang.java.programmer:20707

Show key headers only | View raw


On 12/26/2012 8:22 AM, Stefan Ram wrote:
>    AFAIK 0.1 in hex is 0x1.(9)ap-4, where »(9)« means an
>    infinite sequence of »9«. However, Java only stores a
>    finite number of 9s:
>
> printf( "%a%n", 0.1 )
> 0x1.999999999999ap-4
>
>    . So, since something /positive/ is missing, Javas
>    representation of 0.1 should be /smaller/ than 0.1, but

The conversion of literals to double uses round-to-nearest, with
round-to-even as tie breaker.

The BigDecimal representations of the two exact double values bracketing
decimal 0.1 are:

0.1000000000000000055511151231257827021181583404541015625
0.09999999999999999167332731531132594682276248931884765625

The first is too big by about 5e-18. The second is too small by about
8e-18. It would be a serious bug in the string to double conversion for
the literal if Java picked the second.

The "a" in "0x1.999999999999ap-4" is the last digit of the hex fraction.

>   Removing more 9s makes the value even larger!
>
> println( new java.math.BigDecimal( 0x1.999999999999ap-4 ));
> 0.1000000000000000055511151231257827021181583404541015625

Moving that "a" further to the left increases its significance, and
therefore the overall value.

Patricia

Back to comp.lang.java.programmer | Previous | Next | Find similar | Unroll thread


Thread

Re: Floating Point Representation (Question) Patricia Shanahan <pats@acm.org> - 2012-12-26 09:40 -0800

csiph-web