AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Neuer Zahlentyp - Int128

Ein Thema von Flogo · begonnen am 11. Mai 2003 · letzter Beitrag vom 30. Mai 2003
 
jbg

Registriert seit: 12. Jun 2002
3.485 Beiträge
 
Delphi 10.1 Berlin Professional
 
#3
  Alt 11. Mai 2003, 11:05
Zitat von tommie-lie:
IntToStren
Das ist gar nicht nötig.
1. Ist es relativ langsam
2. Wenn man schon Werte von 0..9 hat, kann man gleich Ord('0') dazurechnen und hat die Ziffer.

Delphi-Quellcode:
type
  TDezZahl = record
    Negativ: Boolean;
    Stellen: TByteDynArray;
  end;

procedure DezZahlConvertError(const Zahl: string);
begin
  raise EConvertError.CreateFmt('"%s" ist keine gültige Zahl', [Zahl]);
end;

function DezZahlToStr(const Zahl: TDezZahl): string;
var
  i: Integer;
  StartIndex: Integer;
begin
  if Zahl.Negativ then StartIndex := 2 else StartIndex := 1;
  SetLength(Result, Length(Zahl.Stellen) + StartIndex - 1);

  if Zahl.Negativ then
    Result[1] := '-';

  for i := 0 to High(Zahl.Stellen) do
    Result[i + StartIndex] := Char(Ord('0') + Zahl.Stellen[i]);
end;

function StrToDezZahl(const Zahl: string): TDezZahl;
var
  i: Integer;
  StartIndex: Integer;
begin
  if (Length(Zahl) = 0) or (not (Zahl[1] in ['0'..'9', '-', '+'])) then
    DezZahlConvertError(Zahl);

  Result.Negativ := (Zahl[1] = '-');
  if (Result.Negativ) or (Zahl[1] = '+') then
    StartIndex := 2
  else
    StartIndex := 1;

  SetLength(Result.Stellen, Length(Zahl) - (StartIndex - 1));

  for i := StartIndex to Length(Zahl) - 1 do
  begin
    if not (Zahl[i] in ['0'..'9']) then
      DezZahlConvertError(Zahl);

    Result.Stellen[i - StartIndex] := Byte(Ord(Zahl[i]) - Ord('0'));
  end;
end;
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:25 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz