Autor Beitrag
Schlauchmobil
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Fr 22.10.04 13:36 
Blöde frage, aber wie lass ich z.b. 2 hoch 5 rechnen in delphi?
thx
Elite
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 22.10.04 13:45 
Ich mach so etwas mit einer Schleife:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
 a, ergebnis: integer;
...
ergebis := 1;
for a := 1 to exponent do
 ergebnis := ergebnis * basis;
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Fr 22.10.04 13:53 
oder du bidest die Standardunit Math ein und dann kannste die function Power nutzen. also einfach Power(2,5);

_________________
mfg. Joel
Method_Man
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 22.10.04 14:03 
Bin zwar Anfänger, will aber auch mal ein Vorschlag machen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var
x:Integer
Edit1.text:=x*x*x // x³

//irgendwie so hatte ich es hinbekommen.  :lol:
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Fr 22.10.04 14:16 
Hallo,

@Method_Man: Wenn schon Vorschläge, dann konstruktiv, auf die Frage bezogen und nicht, damit ich auch einmal etwas kundgetan habe. Das Beispiel von Dir kannst Du in den Müll kippen, weil es so nicht funktioniert und darüberhinaus die Frage nicht beantwortet. Die hat nämlich JoelH schon richtig beantwortet.

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Fr 22.10.04 15:42 
Hi!

Alernativ: x = a hoch b:

ausblenden Delphi-Quelltext
1:
x := Exp(b * Ln(a));					


AXMD
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 22.10.04 15:47 
Aber für a > 0!

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Fr 22.10.04 15:49 
Klar :) sry - vergessen zu erwähnen.

AXMD
Luzzifus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 200

Win2K
D6 Prof
BeitragVerfasst: Fr 22.10.04 16:04 
oder für logarithmus dualis (2^x):

function ldexp(const X: Extended; const P: Integer): Extended;

auch unit Math.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 22.10.04 16:25 
@Luzzifus:
Die Exp-Funktion ist bei Delphi Standard. Da braucht man keine Math-Unit.
Luzzifus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 200

Win2K
D6 Prof
BeitragVerfasst: Fr 22.10.04 16:29 
Also ich krieg nen undeclared-identifier-error wenn ich ldexp ohne Math in den uses aufrufe.. ;)
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 22.10.04 16:33 
Die Exp-Funktion.
Nur weil du meintest "auch".
Luzzifus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 200

Win2K
D6 Prof
BeitragVerfasst: Fr 22.10.04 16:36 
sowas von krümelkackerig.. :twisted:

naja halt nur falsch formuliert.. :cry:
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: Fr 22.10.04 17:57 
Für Potenzen der Basis 2 kann man bei Integern auch

x = b * (2 hoch a)

x = b shl a

nehmen. Für a < 0 gilt

x = b shr a

_________________
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.