Skip to content

Commit 5953de5

Browse files
committed
GitKraken
1 parent 3747610 commit 5953de5

File tree

6 files changed

+1808
-1059
lines changed

6 files changed

+1808
-1059
lines changed

Source/Velthuis.BigIntegers.pas

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ interface
188188
// EXPERIMENTAL is set for code that tries something new without deleting the original code yet.
189189
// Undefine it to get the original code.
190190

191-
{$DEFINE EXPERIMENTAL}
191+
{ $DEFINE EXPERIMENTAL}
192192

193193

194194
// --- Permanent settings ---
@@ -10938,6 +10938,9 @@ class function BigInteger.Sqrt(const Radicand: BigInteger): BigInteger;
1093810938
end;
1093910939

1094010940
// Richard P. Brent and Paul Zimmermann, "Modern Computer Arithmetic", Algorithm 1.12
10941+
// Produces square root and square root remainder in one go.
10942+
// Extremely fast, much faster than Newton-Raphson (as used in BaseCaseSqrtRemainder), even for relatively
10943+
// small sizes.
1094110944
class procedure BigInteger.SqrtRemainder(const Radicand: BigInteger; var Root, Remainder: BigInteger);
1094210945
var
1094310946
RadCopy: BigInteger;
@@ -10947,7 +10950,8 @@ class procedure BigInteger.SqrtRemainder(const Radicand: BigInteger; var Root, R
1094710950
RootQ, RemQ: BigInteger;
1094810951
Quot, Rem: BigInteger;
1094910952
begin
10950-
if Radicand.Size < 22 then
10953+
// Note: if the threshold is too small, a stack overflow will occur.
10954+
if Radicand.Size < 10 then
1095110955
begin
1095210956
BaseCaseSqrtRemainder(Radicand, Root, Remainder);
1095310957
Exit;

0 commit comments

Comments
 (0)