Thema: Delphi Mathe Unit

Einzelnen Beitrag anzeigen

Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#3
  Alt 11. Mai 2003, 08:59
Hi,

Einige Funktionen gibt's bereits in der Math unit, daher überflüssig.
PS: Der Source Code ist schlecht formatiert.

Sieht doch besser so aus?

Code:
unit Mathe;

interface

uses SysUtils;

implementation

function Factorielle(X: Integer): Longint;
var
  N: Integer;
begin
  Result := 1;
  for N := 1 to X do
    Result := Result * N;
end;

function Exposant(X: real; Y: Integer): Extended;
var
  N: Integer;
  TEMP: real;
begin
  if Y = 0 then
    Result := 1
  else
  begin
    Result := X;
    TEMP  := X;
    for N := 2 to Y do
      Result := Result * TEMP;
    if Y < 0 then
      Result := 1 / Result;
  end;
end;

function Tan(COS: real; SIN: real): real;
begin
  Result := COS / SIN;
end;

function Pourcent(X: real; Y: Integer): Extended;
begin
  Result := (X / 100) * Y;
end;

//Pour un triangle de pascal
function COEF_BINOMIAL(P: Integer; Q: Integer): real;
begin
  Result := Factorielle(P) / (Factorielle(Q) * Factorielle(P - Q));
end;

function Pythagore(A: real; B: real): real;
begin
  Result := sqrt(sqr(A) + sqr(B));
end;

function PairImpair(X: Integer): Boolean;
begin
  Result := True;
  if (X mod 2 <> 0) then Result := False;
end;

function Fibunacci(X: Integer): Extended;
var
  I: Integer;
begin
  Result := 1;
  for I := 1 to X do
    Result := Result + X;
end;

function DecToDual(X: Longint): string;
begin
  Result := '';
  while (X <> 0) do
  begin
    Result := Result + IntToStr(X mod 2);
    X := X div 2;
  end;
end;

function DualtoDec(X: string): Longint;
var
  I, COUNTER: Integer;
begin
  Result := 0;
  COUNTER := 0; //for Exposant
  for I := Length(X) downto 1 do
  begin
    Result := Result + round(Exposant(StrToInt(X[I]), COUNTER));
    COUNTER := COUNTER + 1;
  end;
end;

end.
Thomas
  Mit Zitat antworten Zitat