29

Does anyone know how to find out the precision of long double on a specific platform? I appear to be losing precision after 17 decimal digits, which is the same as when I just use double. I would expect to get more, since double is represented with 8 bytes on my platform, while long double is 12 bytes.

Before you ask, this is for Project Euler, so yes I do need more than 17 digits. :)

EDIT: Thanks for the quick replies. I just confirmed that I can only get 18 decimal digits by using long double on my system.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880

2 Answers2

38

You can find out with std::numeric_limits:

#include <iostream>     // std::cout
#include <limits>       // std::numeric_limits
int main(){
    std::cout << std::numeric_limits<long double>::digits10 << std::endl;
}
WhiZTiM
  • 21,207
  • 4
  • 43
  • 68
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
6

You can use <cfloat>. Specifically:

LDBL_DIG
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
user7116
  • 63,008
  • 17
  • 141
  • 172