Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some minor Delphi standardization #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Samples/Bernoulli/BigBernoulli.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ uses
// Experimental
Velthuis.BigRationals;

function Bernoulli(n: Uint64): BigRational;
function Bernoulli(n: UInt64): BigRational;
begin
var a: TArray<BigRational>;
SetLength(a, n + 1);
Expand Down
7 changes: 5 additions & 2 deletions Samples/MathConstants/BigEuler.pas
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ function Euler(const Digits: Integer): BigDecimal;
lastResult := Result;
lastFactorial := lastFactorial * iteration;
Result := (Result + BigDecimal.One / lastFactorial).RoundToPrecision(InternalPrecision);
if lastResult = Result then break;
inc(Iteration);

if lastResult = Result then
Break;

Inc(Iteration);
end;
//Writeln(Format('%d digits took %d iterations',[Digits, iteration]));
Result.DefaultRoundingMode := rmFloor;
Expand Down
4 changes: 3 additions & 1 deletion Samples/MathConstants/BigMathConstants.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ uses
function CheckDigits(const Digits1, Digits2: string): UInt64;
begin
for var idx := 1 to Length(Digits1) do
if Digits1[idx] <> Digits2[idx] then exit(idx);
if Digits1[idx] <> Digits2[idx] then
Exit(idx);

Result := 0;
end;

Expand Down
13 changes: 8 additions & 5 deletions Samples/Pi/BigPiConsole.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ function CheckDigits(const Digits1, Digits2: string): UInt64;
begin
Assert(Length(Digits1) = Length(Digits2),
'Calls to Check Digits should include two strings with the same length.');
for var idx := 1 to Length(Digits1) do
if Digits1[idx] <> Digits2[idx] then exit(idx);
Result := 0;

for var idx := 1 to Length(Digits1) do
if Digits1[idx] <> Digits2[idx] then
Exit(idx);

Result := 0;
end;

procedure CompareDigits(digits: UInt64);
Expand Down Expand Up @@ -96,10 +99,10 @@ begin
digits := DigitsToString(Chunk);

// slow down the output for demonstration purposes
for var i := low(digits) to High(digits) do
for var i := Low(digits) to High(digits) do
begin
Write(digits[i]);
sleep(100);
Sleep(100);
end;
end;

Expand Down
8 changes: 6 additions & 2 deletions Samples/Pi/Tests/BBPpiTests.pas
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,20 @@ procedure BBPpiTest.CompareCallbackToResult;

procedure BBPpiTest.HashCheck(const Digits: Integer; const Hash: String);
begin
if digits > 10000 then exit;
if digits > 10000 then
Exit;

var pi := BBPpi(Digits).ToString.Insert(1,'.');
// one more digit for the decimal point
var expectedLength := Succ(Digits);
var actualLength := length(pi);
var actualLength := Length(pi);

Assert.AreEqual(expectedLength, actualLength,
Format('For %d digits, was expecting one more for the decimal, '+
'but received %d.',[digits, actualLength]));

var calcHash := THashMD5.GetHashString(pi);

Assert.AreEqual(hash, calcHash,
Format('Incorrect hash for %d digits with BBPpi. ',[digits]))
end;
Expand Down
12 changes: 8 additions & 4 deletions Samples/Pi/Tests/BigPiChudnovskyTests.pas
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ procedure ChudnovskyPiTest.Check1000Digits;

procedure ChudnovskyPiTest.HashCheck(const Digits: Integer; const Hash: String);
begin
if digits > 5000 then exit;
if digits > 5000 then
Exit;

var pi := Chudnovsky(Digits).ToString;
Assert.AreEqual(Succ(Digits), length(pi));
var calcHash := THashMD5.GetHashString(pi);
Assert.AreEqual(hash, calcHash, Format('Incorrect hash for %d digits with Chudnovsky. ',[digits]))

Assert.AreEqual(Succ(Digits), Length(pi));

var calcHash := THashMD5.GetHashString(pi);

Assert.AreEqual(hash, calcHash, Format('Incorrect hash for %d digits with Chudnovsky. ',[digits]))
end;

initialization
Expand Down
16 changes: 8 additions & 8 deletions Samples/Pi/Tests/BigPiHashTestCaseProvider.pas
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ TPiHash = record
public
constructor Create; override;
//Get the amount of cases we are creating
function GetCaseCount(const methodName : string) : Integer; override;
function GetCaseCount(const methodName: string): Integer; override;
//Get the name of the cases, depending on the Test-Function
function GetCaseName(const methodName : string; const caseNumber : integer) : string; override;
function GetCaseName(const methodName: string; const caseNumber: Integer): string; override;
//Get the Params for calling the Test-Function;Be aware of the order !
function GetCaseParams(const methodName : string ; const caseNumber : integer) : TValuearray; override;
function GetCaseParams(const methodName: string; const caseNumber: Integer): TValuearray; override;
//Cleanup the instance
Destructor Destroy;override;

Destructor Destroy; override;
end;

implementation
Expand Down Expand Up @@ -77,15 +76,16 @@ function TPiHashProvider.GetCaseCount(const methodName: string): Integer;
end;

function TPiHashProvider.GetCaseName(const methodName: string;
const caseNumber: integer): string;
const caseNumber: Integer): string;
begin
Result := Format('Calculate %d digits',[fHashes[caseNumber].Digits]);
Result := Format('Calculate %d digits', [fHashes[caseNumber].Digits]);
end;

function TPiHashProvider.GetCaseParams(const methodName: string;
const caseNumber: integer): TValuearray;
const caseNumber: Integer): TValuearray;
begin
SetLength(Result,2);

Result[0] := fHashes[caseNumber].Digits;
Result[1] := fHashes[caseNumber].Hash;
end;
Expand Down
4 changes: 2 additions & 2 deletions Source/Velthuis.BigIntegers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3030,7 +3030,7 @@ constructor BigInteger.Create(const Bytes: array of Byte);
Limbs: TMagnitude;
Negative: Boolean;
begin
Negative := Bytes[High(Bytes)] > Byte(High(Shortint));
Negative := Bytes[High(Bytes)] > Byte(High(ShortInt));
SetLength(Limbs, (Length(Bytes) + 3) div 4);
if Negative then
Limbs[High(Limbs)] := TLimb(-1);
Expand Down Expand Up @@ -5041,7 +5041,7 @@ function BigInteger.ToOctalString: string;
end;

{$IFNDEF PUREPASCAL}
procedure DivModNativeUInts(Dividend, Divisor: NativeUInt; var Quotient, Remainder: NativeUint);
procedure DivModNativeUInts(Dividend, Divisor: NativeUInt; var Quotient, Remainder: NativeUInt);
{$IFDEF WIN32}
asm
PUSH EBX
Expand Down
4 changes: 2 additions & 2 deletions Source/Velthuis.BigRationals.pas
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ constructor BigRational.Create(const Value: Double);
Exponent: Integer;
Mantissa: Int64;
begin
if IsInfinite(Value) or IsNaN(Value) then
if IsInfinite(Value) or IsNan(Value) then
Error(ecInvalidArg, ['Double']);

if Value = 0.0 then //FI:W542 Direct floating-point comparison
Expand Down Expand Up @@ -609,7 +609,7 @@ function ConvertDoubleToRational(Value, Epsilon: Double; MaxIterations: Integer;
Ratio := 0.0;
LQuot := 0.0;

if IsInfinite(Value) or IsNaN(Value) then
if IsInfinite(Value) or IsNan(Value) then
Error(ecInvalidArg, ['Double']);

LNegative := Value < 0;
Expand Down
4 changes: 2 additions & 2 deletions Source/Velthuis.ExactFloatStrings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function ExactString(const F: Extended): string;
DecimalPoint: Integer;
Len: Integer;
begin
if System.Math.IsNaN(F) then
if System.Math.IsNan(F) then
Exit('NaN')
else if IsNegativeInfinity(F) then
Exit('NegInfinity')
Expand Down Expand Up @@ -117,7 +117,7 @@ function ExactString(const F: Double): string;
DecimalPoint: Integer;
Len: Integer;
begin
if System.Math.IsNaN(F) then
if System.Math.IsNan(F) then
Exit('NaN')
else if IsNegativeInfinity(F) then
Exit('NegInfinity')
Expand Down
2 changes: 1 addition & 1 deletion Source/Velthuis.Sizes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface
CSmallintBits = CWordBits - 1;

// Note: up to XE8, Longword and Longint were fixed sizes (32 bit). This has changed in XE8.
CLongwordBits = CByteBits * SizeOf(Longword);
CLongwordBits = CByteBits * SizeOf(LongWord);
CLongintBits = CLongwordBits - 1;

// Note: up to XE8, Integer and Cardinal were platform dependent. This has changed in XE8.
Expand Down
6 changes: 3 additions & 3 deletions Visualizers/Velthuis.BigIntegers.Visualizers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ TDebuggerBigIntegerVisualizer = class(TInterfacedObject,
procedure Destroyed;
procedure Modified;
// IOTAThreadNotifier160
procedure EvaluateComplete(const ExprStr, ResultStr: string; CanModify: Boolean; ResultAddress: TOTAAddress; ResultSize: Longword; ReturnCode: Integer); overload;
procedure EvaluateComplete(const ExprStr, ResultStr: string; CanModify: Boolean; ResultAddress: TOTAAddress; ResultSize: LongWord; ReturnCode: Integer); overload;
procedure EvaluateComplete(const ExprStr, ResultStr: string; CanModify: Boolean; ResultAddress, ResultSize: LongWord; ReturnCode: Integer); overload;
end;

Expand Down Expand Up @@ -148,7 +148,7 @@ procedure TDebuggerBigIntegerVisualizer.EvaluteComplete(const ExprStr, ResultStr
end;

procedure TDebuggerBigIntegerVisualizer.EvaluateComplete(const ExprStr, ResultStr: string; CanModify: Boolean;
ResultAddress: TOTAAddress; ResultSize: Longword; ReturnCode: Integer);
ResultAddress: TOTAAddress; ResultSize: LongWord; ReturnCode: Integer);
begin
FCompleted := True;
if ReturnCode = 0 then
Expand All @@ -162,7 +162,7 @@ function TDebuggerBigIntegerVisualizer.GetReplacementValue(const Expression,
CurThread: IOTAThread;
ResultStr: array[0..255] of Char;
CanModify: Boolean;
ResultAddr, ResultSize, ResultVal: Longword;
ResultAddr, ResultSize, ResultVal: LongWord;
EvalRes: TOTAEvaluateResult;
Services: IOTADebuggerServices;
Done: Boolean;
Expand Down