Skip to content

Error in Prime.pas, results wrong overwrite #19

Description

@SiveaITA

In Velthuis.BigIntegers.Primes.pas there is a bug: in the NextProbePrime function the results are always overwrite at the end of the execution block.

function NextProbablePrime(const N: BigInteger; Precision: Integer): BigInteger;
var
  Two: BigInteger;
begin
  Two := 2;
  Result := N;
  if Result = Two then
    Exit;
  if Result.IsEven then
    Result := Result.FlipBit(0);
  while not IsProbablePrime(Result, Precision) do
  begin
    Result := Result + Two;
  end;
  Result := N;                               //<-----------------------This line should be removed
end;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions