• 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

Single precision /double precision?

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an idea as to what float and double are all about.
But dont understand what single precision and double precision mean.
How does one limit the accuracy of double variables to .........say 6 decimal places.

[ UD: removed superfluous duplicated questions marks ]
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't limit the precision (not "accuracy") of a double to 6 significant [decimal] figures. A normalised double uses 53 bits of precision, which is 53 * log2 = 15.96 decimal places.
You can print out a double with the %e tag; you will have to check its details in Formatter, but you can probably get that to display 6 sig fig.

A double is classed as double-precision, using 64 bits; there are specifications for quadruple-precision floating point numbers (128 bits, not used in Java) and single-precision (32 bits, called float in Java). A normalised float has 24 bits' precision which is equivalent to 7.3 [decimal] significant figures, so that might solve your problem.
 
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic