BlueSpruce
Active member
- Local time
- Today, 17:44
- Joined
- Jul 18, 2025
- Messages
- 781
In my other Watercooler post about "Showcase Your Relics" I mentioned the first basic program I wrote in high school for finding perfect numbers. The thread detoured into that topic when I posted vba code to find perfect numbers. So I am forking this new thread to continue with that topic here, and other pure mathematics, such as number theory. @RonPaii ran the vba code that has nested loops and it's very cpu intensive.
https://www.access-programmers.co.uk/forums/threads/showcase-your-relics.334801/post-1978860
I asked AI to generate vba code to accurately calculate pi to 100K decimal places and AI said VBA is not an adequate language for that task because the supported datatypes, such as variant, can only go up to 28 significant digits. AI is suggesting to build custom functions for supporting BigInt mathematical operations. Here's what AI provided, Your thoughts?
 https://www.access-programmers.co.uk/forums/threads/showcase-your-relics.334801/post-1978860
I asked AI to generate vba code to accurately calculate pi to 100K decimal places and AI said VBA is not an adequate language for that task because the supported datatypes, such as variant, can only go up to 28 significant digits. AI is suggesting to build custom functions for supporting BigInt mathematical operations. Here's what AI provided, Your thoughts?
Calculating Pi to 100,000 decimal places in VBA is not practical or accurate due to the limitations of VBA's built-in data types. The standard Double type only provides about 15 digits of precision, and the Decimal type, a subtype of Variant, is limited to 28 digits. Achieving a much higher precision of 100,000 digits requires a custom-built "Big Number" or "BigInt" library to handle large-scale arithmetic.
Instead of a single VBA module, a complete solution would involve creating your own library for string-based arithmetic. The code below provides a proof-of-concept for the fundamental math functions needed, based on an archived tutorial by Tushar Mehta. It then applies these functions to a highly efficient Machin-like formula to compute Pi.
Big number arithmetic functions
Starting with a smaller number like 10,000 is recommended to test the code before attempting 100,000 digits, which will be very time-consuming.
Code:Option Explicit '------------------------------------------------------------------------------------------------------------------------------------------------ ' basCalculatePi: Module to compute Pi using a Machin-like formula and the BigInt library. '------------------------------------------------------------------------------------------------------------------------------------------------ Public Function CalculatePi(ByVal numDigits As Long) As String ' Computes Pi to the specified number of decimal places using the formula: π/4 = 4*arctan(1/5) - arctan(1/239) Dim arctan1_5 As String Dim arctan1_239 As String Dim term1 As String, term2 As String, piStr As String ' Calculate the arctan series for each term arctan1_5 = ArctanSeries("1", "5", numDigits + 5) arctan1_239 = ArctanSeries("1", "239", numDigits + 5) ' Perform the main calculation using BigInt functions term1 = BigMultiply(BigMultiply(arctan1_5, "4"), "4") term2 = BigMultiply(arctan1_239, "4") ' This term in the formula should be BigSubtract(term1, BigMultiply(arctan1_239, "4")) for the whole pi. Please refer to an accurate Machin-like formula definition. piStr = BigSubtract(term1, term2) ' Assuming term2 is calculated as 4 * arctan(1/239). Please verify the formula implementation. ' Format the final result CalculatePi = Left$(piStr, numDigits + 1) End Function Private Function ArctanSeries(ByVal num As String, ByVal denom As String, ByVal precision As Long) As String ' Computes the Taylor series for arctan(num/denom) = x - x^3/3 + x^5/5 - x^7/7 + ... where x = num/denom. ' ... (Full function code implementing the series calculation) End Function
 
	 
 
		 
 
		 
 
		 
					
				

 
 
		 
 
		