• Post Reply Bookmark Topic Watch Topic
  • New Topic

Very long double values...  RSS feed

 
Adam Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm doing some testing, and for my test data need to work out the various boundaries of double values...

I've worked out that any smaller value than
0.0000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000001

...will throw a compile error. Seems fair enough really However, when I put in a number 0.9999999...and so on... however many digits I add to the end - I never get an error. Also, when I print this stored in a double to screen - it rounds it up to 1!!

Can anyone help me and explain this behaviour?

Thanks
Adam

[I inserted some line breaks so the other posts wouldn't be horribly distorted - Jim]
[ April 06, 2005: Message edited by: Jim Yingst ]
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a bit of a discussion about this over in the intermediate forum.

Basically, you need to look at how a double is represented internally.

It consists of 8 bytes: 1 sign bit, 11 bit exponent and 52 bit mantissa.

Try this document which runs through some examples and an explaination: here.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37496
540
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam,
Also note that if you actually needed this level of precision, you should use BigDecimal.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!