3

You can see Ramanujan's constant.
Here is my code:

#include <iostream>
#include <math.h>
#define _USE_MATH_DEFINES
using namespace std;

int main ()
{
long double s=sqrt(163);
long double P=M_PI;
long double R=exp(s*P);

cout.precision(150);

cout<<"Pi=  "<<P<<"\n"<<"sqrt(163)=  "<<s<<"\n"<<"R=  "<<R;
return(0);
}   

This is my out put:

Pi=  3.141592653589793115997963468544185161590576171875
sqrt(163)=  12.767145334803704059822848648764193058013916015625
R=  262537412640768256  

What's wrong with my program?
The correct output is 262537412640768743.99999999999925...

Ab_Sh
  • 133
  • 6

2 Answers2

6

A double has about 15 decimal digits of precision.

Your program uses M_PI, which is a double, not a long double.

Your answer therefore has about 15 digits of precision.

Community
  • 1
  • 1
Drew Dormann
  • 59,987
  • 13
  • 123
  • 180
1

80-bit precision mode for long double with Intel C++ is invokedwhen you set the long-double option in the compile line. As you will see in the Intel C++ documentation,80-bit long double is 16-byte aligned, so sizeof(long double) is 16.

All Windows and linux x64 compilers take SSE as the default mode, with all float and double data taken as SSE data types. In the early development of Windows x64, 80-bit x87 data were prohibited. Thisrestriction was relaxed by the time of full release, but Windows library support is lacking. In linux, long double support should be compatible with gcc.

80-bit long double will have the same issues with any x64 compiler; expressions with mixed data types float/long double or double/long doublecould be inefficient, due to the conversion between SSE and x87 data. If the gcc option -mfpmath=387 presents a partial solution, it would be at the expense of many of the usual optimizations for double and float data types, but there is no such option for icc.

From:

[IntelSupportForum][1]
Arif Burhan
  • 507
  • 4
  • 12