Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Floating Point Representation (Question) (http://www.velocityreviews.com/forums/t955835-floating-point-representation-question.html)

 Stefan Ram 12-26-2012 04:22 PM

Floating Point Representation (Question)

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

println( new java.math.BigDecimal( 0.1 ))
0.100000000000000005551115123125782702118158340454 1015625

shows me a value that is /greater/ than 0.1?

Removing more 9s makes the value even larger!

println( new java.math.BigDecimal( 0x1.999999999999ap-4 ));
0.100000000000000005551115123125782702118158340454 1015625

println( new java.math.BigDecimal( 0x1.9ap-4 ))
0.10009765625

 Stefan Ram 12-26-2012 06:05 PM

Re: Floating Point Representation (Question)

Patricia Shanahan <pats@acm.org> writes:
>The "a" in "0x1.999999999999ap-4" is the last digit of the hex fraction.

For some reason, I did not understand this, but thought »ap«
was a unit marking the start of the exponent (already
wondering »Why /two/ letters?«). Now that you have told me
this, I understand it all - thank you!

 Eric Sosman 12-26-2012 06:36 PM

Re: Floating Point Representation (Question)

On 12/26/2012 11:22 AM, Stefan Ram wrote:
> AFAIK 0.1 in hex is 0x1.(9)ap-4, where »(9)« means an
> infinite sequence of »9«.

What's the "a" for? ;-)

> However, Java only stores a
> finite number of 9s:
>
> printf( "%a%n", 0.1 )
> 0x1.999999999999ap-4

"One, point, twelve nines, A, exponent." See the "A?"

--
Eric Sosman
esosman@comcast-dot-net.invalid

 All times are GMT. The time now is 09:24 PM.