ERLEDIGT
NEIN
NEIN
ANTWORTEN
4
4
ZUGRIFFE
1092
1092
EMPFEHLEN
-
Hallo

Ich habe eine Frage...
Gibt's da einen Datentypen, der mehr Nachkommastellen als long double bietet?
Ich möchte die Zahl Pi mit mehr Nachkommastellen speichern, aber long double kürzt die Zahl zu sehr ab.
Schon mal danke!
Gruß
diviner
-
18.06.06 14:00 #2
- Registriert seit
- Apr 2002
- Ort
- Delmenhorst (Niedersachsen)
- Beiträge
- 3.567
moin
Das -> http://www.swox.com/gmp/ dürfte dir weiterhelfen.
mfg
Tobias
-
Danke Tobias

Werde es mir anschauen.
Gruß
diviner
-
Blicke da überhaupt nicht durch, wie man es einsetzt bzw. installiert...
Geschweige davon, wie man es in einem Programm benutzen kann.
Kennst du dich mit GMP aus, Tobias?
-
Hallo,
wie man es installiert kannst du hier finden:
http://www.cs.nyu.edu/exact/core/gmp/
wie man gmp anwendet und damit PI auf ca 20000 Stellen genau berechnen kann
zeigt dir folgender Code:
Code c:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#include <stdio.h> #include <gmp.h> #define PRECISION 65536 void init_a(mpf_t a){ mpf_init2(a, PRECISION); mpf_set_ui(a, 1); } void init_b(mpf_t b){ mpf_t sqrt2; mpf_init2(b, PRECISION); mpf_init2(sqrt2, PRECISION); mpf_sqrt_ui(sqrt2, 2); mpf_ui_div(b, 1, sqrt2); } void init_c(mpf_t c){ mpf_init2(c, PRECISION); mpf_set_d(c, 0.25); } void init_alpha(mpf_t alpha){ mpf_init2(alpha, PRECISION); mpf_set_ui(alpha, 1); } void calc_a(mpf_t a, mpf_t b){ mpf_add(a, a, b); mpf_div_ui(a, a, 2); } void calc_b(mpf_t b, mpf_t y){ mpf_t mul_res; mpf_init2(mul_res, PRECISION); mpf_mul(mul_res, b, y); mpf_sqrt(b, mul_res); } void calc_c(mpf_t c, mpf_t a, mpf_t alpha, mpf_t y){ mpf_t sub_res; mpf_t mul_res; mpf_init2(sub_res, PRECISION); mpf_init2(mul_res, PRECISION); mpf_sub(sub_res, a, y); mpf_mul(sub_res, sub_res, sub_res); mpf_mul(mul_res, sub_res, alpha); mpf_sub(c, c, mul_res); } void calc_alpha(mpf_t alpha){ mpf_mul_ui(alpha, alpha, 2); } void approx_pi(unsigned int n, mpf_t pi){ mpf_t alpha, y, a, b, c, sum, mul; int i = 0; init_alpha(alpha); init_a(a); init_b(b); init_c(c); mpf_init2(y, PRECISION); mpf_init2(pi, PRECISION); mpf_init2(sum, PRECISION); mpf_init2(mul, PRECISION); for(i = 0; i < n; i++){ mpf_set(y, a); calc_a(a, b); calc_b(b, y); calc_c(c, a, alpha, y); calc_alpha(alpha); mpf_add(sum, a, b); mpf_mul(sum, sum, sum); mpf_mul_ui(mul, c, 4); mpf_div(pi, sum, mul); } } int main(){ mpf_t pi; int bytes_written = 0; approx_pi(20, pi); bytes_written = mpf_out_str(stdout, 10, 0, pi); printf("\nBytes written: %d\n", bytes_written); }
Siehe dazu auch:
http://www.uni-leipzig.de/~sma/pi_ei.../ausblick.html
Gruß,
RedWing"I'm not deaf, I'm ignoring you"
----
Ähnliche Themen
-
ROUND(x, d) Long oder Integer statt Double! Liegt es an Hibernate?
Von ThirdKeeper im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 4Letzter Beitrag: 13.11.09, 13:36 -
Fehlermeldung cannot find symbol (class long /double)
Von bloodline im Forum JavaAntworten: 1Letzter Beitrag: 28.11.06, 16:59 -
long double
Von Oll i im Forum C/C++Antworten: 3Letzter Beitrag: 22.09.06, 02:49 -
dem 16 bit Teilsystem mehr ressourcen zur verfügung stellen
Von Jan-Frederik Stieler im Forum Microsoft WindowsAntworten: 10Letzter Beitrag: 14.12.05, 11:41 -
Double-Wert auf zwei Stellen Runden
Von MAN im Forum C/C++Antworten: 10Letzter Beitrag: 21.06.04, 12:49





Zitieren
Login






