Autor Beitrag
luckyluc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 103



BeitragVerfasst: Sa 07.02.09 14:56 
hallo
ich hab hier im forum schon gesucht und auch gegoogelt, jedoch find ich nichts passendes. also ich muss eine zahl bis 2^64 ausgeben. da reicht auch nicht int64 und extended. nach bigint hab ich auch gesucht, wie gesagt kann damit nicht richtig was anfangen. weiß nicht wie ich damit ungehen soll. vlt. könnt ihr mir helfen.
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 07.02.09 15:16 
Wozu brauchst Du es denn konkret?

Int64 sind 64 Bit (inkl. Vorzeichen), den kann man sich aber ggf. zu Nutze machen, aber das ist eine andere Geschichte ...

Und bzgl. BigInt: Wo scheiterst Du denn?

_________________
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.
luckyluc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 103



BeitragVerfasst: Sa 07.02.09 15:20 
also das hier ist mein quelltext
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
var 
 Form1: TForm1;  
schachbrett : array [1..8,1..8] of Int64
procedure TForm1.Button1Click(Sender: TObject);
var  i, b_stabe, zahl: integer;
begin  
i:= 1; 
for b_stabe:= 1 to 8 do   
for zahl := 1 to 8 do     
begin        
schachbrett[b_stabe,zahl]:= i;    
i := i*2;       
end;

for b_stabe:= 1 to 8 do   
for zahl := 1 to 8 do 
StringGrid1.Cells[b_stabe,zahl] := IntToStr(schachbrett[b_stabe,zahl]); 

  
end;

bze. bigint: ja da gibts ja so fertige units die man sich doloaden kann ka wie ich die einsetzten soll.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 07.02.09 15:24 
Gemäss deiner Source reicht dir auch 2^63. Nimm eine UInt64, die geht bis 2^64-1.
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 07.02.09 15:42 
@BigInt-Units: Downloaden, in deinen Projekt-Ordner legen, in deinem Projekt in deiner Unit, wo du sie verwenden willst in die Uses aufnehmen, die Funktionen aus den Units verwenden.

_________________
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.
luckyluc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 103



BeitragVerfasst: Sa 07.02.09 16:10 
danke! werd mal beides versuchen. doch wie gebe ich Uint64 ein? also ich hab so gemacht
ausblenden Delphi-Quelltext
1:
var  Form1: TForm1;  schachbrett : array [1..8,1..8] of UInt64					

Muss ich da sonst noch was ändern, denn bei mir werden immernoch erst die hälfte aller zahlen angegeben?
luckyluc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 103



BeitragVerfasst: Sa 07.02.09 17:19 
das mit dem UInt64 funkt. einfach nicht. kann mir jemand helfen?
jfheins
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 918
Erhaltene Danke: 158

Win 10
VS 2013, VS2015
BeitragVerfasst: Sa 07.02.09 17:22 
Extended müsste doch locker ausreichen !?

Zugegeben, bei großen Zahlen lässt die Genauigkeit nach, aber auf 10 Stellen sollte doch reichen?
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Sa 07.02.09 17:23 
user profile iconjfheins hat folgendes geschrieben Zum zitierten Posting springen:
Extended müsste doch locker ausreichen !?

Zugegeben, bei großen Zahlen lässt die Genauigkeit nach, aber auf 10 Stellen sollte doch reichen?

Wenn ich das richtig verstanden habe, geht es hier um ganze Zahlen. Und Extended packt 2^64 garantiert nicht - mit der Genauigkeit müssten das dann ja riesige Datenmengen werden.
luckyluc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 103



BeitragVerfasst: Sa 07.02.09 17:26 
ne extended reicht nicht wollt jetzt ma l uint64 ausprobieren, irgenwie funkt das auch nicht. wo liegt der fehler?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 07.02.09 17:28 
user profile iconluckyluc hat folgendes geschrieben Zum zitierten Posting springen:
das mit dem UInt64 funkt. einfach nicht. kann mir jemand helfen?
Du hast vorhin bereits nach nicht einmal einer Stunde gepusht.
user profile iconluckyluc hat folgendes geschrieben Zum zitierten Posting springen:
es wäre nett, wenn mir mal jemand antworten würde. danke.
Und jetzt ist es auch ca. eine Stunde erst her.

Schiebeposts sind hier erst nach 24 Stunden erlaubt :!:

user profile iconluckyluc hat folgendes geschrieben Zum zitierten Posting springen:
ne extended reicht nicht wollt jetzt ma l uint64 ausprobieren, irgenwie funkt das auch nicht. wo liegt der fehler?
Ich kenne das auch nicht, meines Wissens gibt es nur UInt32, aber keine unsigned Variante von Int64.

user profile iconluckyluc hat folgendes geschrieben Zum zitierten Posting springen:
ne extended reicht nicht
Das geht bis 1.1 x 10^4932 ;-)
luckyluc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 103



BeitragVerfasst: Sa 07.02.09 18:00 
ich hab es aber mit extended auprobiert und das programm hat nur die hälfte der zahlen ausgeggeben und nicht alle zahlen (bis 2^63).
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Sa 07.02.09 18:17 
Oh, wir sind schon auf 2^63 runter. Dann reicht ja Int64...
ausblenden Delphi-Quelltext
1:
2:
  ShowMessageFmt('high(int64)=%d',[high(Int64)]);
  ShowMessageFmt('that is 2^%f',[Log2(high(Int64))]);

(Log2 gibts in der Unit Math)

Probiers mal aus ;)

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
klausiemausie
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

Win XP, Win Vista Ultimate
Delphi 6
BeitragVerfasst: Sa 07.02.09 18:25 
wir haben dieses selbe programm mal in der schule programmiert, das is doch wenn ich das richtig sehe, die aufgabe, ein schachbrett und auf jedem feld soll die doppelte anzahl von keine ahnung, bratäpfeln oder was auch immer liegen , wie auf dem nachbarfeld, beginnend oben links mit 1. und bei mir hat extended so weit ich weiss ausgereicht, wenn nich dann wars doubleextended, was anderes habe ich nicht gebraucht. wenn dann muss der fehler irgendwo anders liegen.
gruss klaus
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 07.02.09 18:25 
user profile iconMartok hat folgendes geschrieben Zum zitierten Posting springen:
Oh, wir sind schon auf 2^63 runter. Dann reicht ja Int64...
ausblenden Delphi-Quelltext
1:
  ShowMessageFmt('high(int64)=%d',[high(Int64)]);					
Nein, das ist falsch, das reicht nicht. Int64 geht bis von -2^63 bis 2^63 - 1, deshalb geht es direkt so nicht.

Möglichkeiten:
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:
procedure TFormXY.ButtonXYClick(Sender: TObject);

  function My2Power(Exponent: Integer): String;
  var
    Tmp: Byte;
    i, j: Integer;
  begin
    if Exponent <= 62 then
      Result := IntToStr(Int64(1) shl Exponent)
    else
    begin
      Result := IntToStr(Int64(1) shl 62);
      for j := Exponent downto 63 do
      begin
        Tmp := 0;
        for i := Length(Result) downto 1 do
        begin
          Tmp := 2*(Ord(Result[i]) - 48) + Tmp;
          Result[i] := Chr((Tmp mod 10) + 48);
          Tmp := Tmp div 10;
        end;
        if Tmp <> 0 then
          Result := Chr(Tmp + 48) + Result;
      end;
    end;
  end;

  function My2PowerEasy(Exponent: Integer): String;
  begin
    Result := IntToStr(Int64(1) shl Exponent);
    if Exponent = 63 then
      Delete(Result, 1, 1)
    else if Exponent > 63 then
      raise Exception.Create('Exponent zu groß, mehr als 63 geht so nicht!');
  end;

begin
  ShowMessage(My2PowerEasy(63));
  ShowMessage(My2Power(63));
end;
My2PowerEasy ist kurz, geht aber nur bis 2^63, My2Power geht beliebig hoch, ist aber nicht besonders schnell, wenn die Exponenten größer als 62 werden.
luckyluc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 103



BeitragVerfasst: Sa 07.02.09 18:39 
@[quote]klausiemausie:
siehst du denn dann oben in meinem quelltext irgendwo en fehler?
wie konnte es denn bei dir mit extended funkt.?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 07.02.09 18:46 
Mit Extended werden die Zahlen nicht komplett dargestellt sondern ggf. mit Exponent, und das willst du ja vermutlich nicht.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 07.02.09 18:55 
Bei mir geht das auch mit Extended, ab 2^50 ist das dann wissenschaftliche Notation.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 07.02.09 19:00 
user profile iconDeddyH hat folgendes geschrieben Zum zitierten Posting springen:
ab 2^50 ist das dann wissenschaftliche Notation.
Genau um diese größeren Zahlen geht es ja. Und ich nehme einmal an, dass genau diese Darstellung ohne alle Stellen das Problem mit Extended war. :mrgreen:
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 07.02.09 19:06 
Das lese ich aus der Problembeschreibung aber nicht heraus, da steht nur "es reicht nicht".