PI in C++?
-
gordon schrieb:
#define PI 3.14159265
dann kannst du es normal verwenden, z.B. pi2 = PI*2
geht aber auch const double PI = 3.14159265
usw..
Danke,das mit #define,denn da hab ich was neues wieder dazugelernt,danke

-
inline double PI() { __asm fldpi } int main() { std::cout << PI() << std::endl; }
Aber nur für MS'ler :-}
-
#include <iostream> #include <conio.h> inline double PI() { __asm ( "fldpi" ); } int main() { std::cout << PI() << std::endl; getch(); }1.#QNAN Was ist das?
-
inline double PI() { __asm fldpi; } int main() { std::cout << PI(); }3.14159
passt!

-
hehe? schrieb:
#include <iostream> #include <conio.h> inline double PI() { __asm ( "fldpi" ); } int main() { std::cout << PI() << std::endl; getch(); }1.#QNAN Was ist das?
mach
inline double PI() { double pi; __asm ( "fldpi" : "=t" ( pi ) ); return pi; }daraus
-
So geht's auch:
#include <iostream> #include <cmath> int main() { std::cout << M_PI << std::endl; }mfg.
-
yep!

-
joomoo schrieb:
So geht's auch:
#include <iostream> #include <cmath> int main() { std::cout << M_PI << std::endl; }Das ist aber reiner Zufall. M_PI gehört jedenfalls nicht zum Standard.
-
-
so geht's in jedem Fall mit Standard-C++
#include <iostream> #include <cmath> const double PI = std::acos(-1.0); // oder 4*std::atan(1.0) int main() { using namespace std; cout << "PI = " << PI << endl; return 0; }und ist so genau, wie es der double hergibt.
Gruß
Werner