No matter how high I set D, it seems like testing enough numbers finds one where the formula returns the wrong value.
You will always get an error if you test a sufficient number of digits - the algorithm does not use arbitrary accuracy, so rounding errors will ultimately be displayed.
Unlimited iteration with a gap, when the digit does not change, it will be difficult to determine the minimum accuracy required for a given number of digits.
It is best to determine it empirically, ideally, by comparing with a known correct source and increasing the number of digits until you get a match, or if the correct source is not available, start with maximum accuracy (which I guess is 14, since the 15th the figure almost always contains a rounding error.)
EDIT: more precisely, the algorithm includes a cycle - from 0..n, where n is the number to calculate. Each iteration of the loop will result in some error. After looping a sufficient number of times, the error will encroach on the most significant digit that you calculate, and therefore the result will be incorrect.
The wikipedia article uses 14 digits of accuracy, and this is enough to correctly calculate the number 10 ** 8. As you have shown, fewer digits lead to errors that occur earlier, because there is less accuracy, and the error becomes visible with fewer iterations . The end result is that the value for n, for which we can correctly calculate the digit, becomes lower with fewer digits.
If you have D hexadecimal digits of precision, then D * 4 bits. An error of 0.5 bits is introduced with each iteration in the smallest bit value, therefore, with 2 iterations, the probability that the LSB is erroneous. During the summation, these errors are added and accumulated. If the number of total errors reaches the least significant digit in the most significant digit, then the one digit you choose will be incorrect. Roughly speaking, this is when N> 2 ** (D-0.75). (Correct some logarithmic base.)
Empirically extrapolating your data, it seems that the approximate match is N = ~ (2 ** (2.05 * D)), although there is some data, so this may not be an accurate predictor.
The BBP algorithm you have chosen is iterative, so it takes a longer time to calculate the numbers in the sequence. To calculate the numbers 0..n, follow steps O(n^2) .
The Wikipedia article provides a formula for calculating the nth digit, which does not require iteration, just raising to a power and rational numbers. This will not lead to the same loss of accuracy as the iterative algorithm, and you can calculate any digit pi as needed in constant time (or, in the worst case, the logarithmic type, depending on the implementation of exponentiation with a module), so computing n digits will take O(n) time, possibly O (n log n).