Thursday, January 7, 2016

Using the inbuilt PI value

//updated on 12/19/2021
In the header add following lines.

struct Pi
      {
            inline operator double() const
            {
                  double x;         // memory location to store the value
                  __asm fldpi;      // Load constant pi onto stack
                  __asm fstp x;     // create floating point store
                  return x;         //  return value
            }
      };

      static Pi PIE;

Let us say the above was added to "GenericHeader.h"

Then the following code is an example of using it.

#include <iostream>
#include "GenericHeader.h"

using namespace std; 

int main(){

double x = PIE;
cout << PIE << endl; 
  return 0; 
}