Autor Beitrag
Cybo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 87

Win 95/98/xp/NT Suse Linux
D7 Ent
BeitragVerfasst: Sa 27.09.03 23:35 
HI Leute,

wie kann ich Wurzeln ziehen oder Potenzieren?

Wenn ich var1^2 als code nutze bekomme ich einen Fehlermeldung, dass "ein Zeigertyp erwartet wird".


Helft mir...

Cybo

_________________
Ich öffnete, kompilierte und traute meinen Augen nicht.
Raphael O.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1596


VS 2013
BeitragVerfasst: Sa 27.09.03 23:51 
Quadratwurzel:sqrt(intvar);
Quadrat:sqr(intvar);

ausblenden Quelltext
1:
Power(const Base, Exponent: Extended): Extended;					
Cybo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 87

Win 95/98/xp/NT Suse Linux
D7 Ent
BeitragVerfasst: So 28.09.03 00:07 
Herzlichen Dank, es funktioniert einwandfrei..

Cybo

_________________
Ich öffnete, kompilierte und traute meinen Augen nicht.
jo_gammler
Hält's aus hier
Beiträge: 15

Win XP, Linux Kubuntu, Win 95
Delphi 5
BeitragVerfasst: Mo 16.04.07 15:05 
Hi der Thread ist en bisschen alt ich grab ihn mal wieder aus!

Hab auch ein Programm geschrieben zum Wurzeln rechenen hier der Code

ausblenden volle Höhe Delphi-Quelltext
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:
  public
    { Public declarations }
    a,b,c,d:real;
    ds:string;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var i:integer         ;
begin
a:=strtofloat(edit1.text);
b:=0;

repeat          //rechte grenze
b:=b+1;
until b*b>a;

c:=b-1;

ds:=floattostr(c)               ;

label2.Caption:=ds;
label3.Caption:=floattostr(c);
label4.Caption:=floattostr(b);

for i:= 1 to 100 do begin;
if a=c*c then label2.Caption:=floattostr(c)
else begin
if a>((b+c)/2)*((b+c)/2)
then c:=(b+c)/2
else b:=(b+c)/2;

label3.Caption:=floattostr(c);
label4.Caption:=floattostr(b);
memo1.Lines.Add(floattostr(c)) ;
memo1.Lines.Add(floattostr(b))  ;
end;

end;
end;

end.


ich komme aber nie mehr als auf glaub 13 Stellen :( woran liegt das und wie kann ich das ändern?

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Mo 16.04.07 15:12 
Versuchs mit dem Variablentyp Extended statt Real, aber... Wenn ich eine Wurzel ziehen will, sagen wir die .. fünfte aus 10 dann mach ich Power(101/5) :gruebel:
PS: Es würde die Lesbarkeit deines Codes verbessern, wenn du delphi- statt code-Tags benutzen würdest.
PPS: Ausserdem solltest du dir eine ordentliche Formatierung angewöhnen, ich empfehle den Suche bei Google DELFOREXP SOURCE FORMATTER

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
jo_gammler
Hält's aus hier
Beiträge: 15

Win XP, Linux Kubuntu, Win 95
Delphi 5
BeitragVerfasst: Mi 18.04.07 22:08 
Sry wegn meinem Programmierstiel.
Habs jetzt mit extended versucht bringt immer noch nur 13 stellen.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Fr 20.04.07 22:55 
Das Problem ist, dass ein Computer nicht mit unendlich vielen Stellen rechnen kann, zumindest nicht von Natur aus. Was du machen kannst, ist dir vom Prinzip her, einen eigenen Datentyp schreiben. Das ist ... Nun, da musst du sämtliche Berechnungen selbst vornehmen. Ob es eine einfachere Lösung gibt, weiß ich nicht.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 21.04.07 21:21 
Wie JayEff bereits korrekt beschreibt, musst Du für die BErechnung mit beliebig vielen Nachkommastellen eine eigene Implementierung der Rechenoperationen vornehmen. Hört sich auf den ersten Blick zwar kompliziert an, ist es aber nur bedingt. Wenn Du verstanden hast, wie Du das stellenweise Rechenen im Dezimalsystem einem Computer beibringst, dann kannst Du auch relativ einfach dieses Verhalten übertragen, um z.B. mit dem Newton-Verfahren die Wurzel zu berechnen (mit eben beliebig vielen Nachkommastellen).

Hab neulich erst mit nem Kommulitonen ne Semester-Arbeit über eine Gleitkomma-Bibliothek mit beliebig vielen Nachkommastellen geschrieben. Die war aber nicht auf Wurzeln begrenzt, sondern konnte jegliche Grundrechenarten, Potenzbasierten Funktionen (Exp, Ln, Power) sowie alle Winkel- und Hyperbolischen Winkel-Funktionen sowie deren Umkehrungen. Insgesamt hatte unser Projekt (ANSI C 99 auf Konsole incl. Infix-Parser, und Integer-Bibliothek und Doku) rund 9800 Zeilen.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.