• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Very long double values...

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adam,
Also note that if you actually needed this level of precision, you should use BigDecimal.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic