PI class
The PI
class provides methods for calculating the value of pi using
various algorithms, such as the Chudnovsky, Gauss-Legendre, and BBP algorithms.
It also includes methods for retrieving individual digits, checking for
digit patterns, and performing computations that require the value of pi.
The precision
parameter in the constructor determines the number of
decimal places to compute for the value of pi. If no precision
is
provided, the default is 100 decimal places.
The computed value of pi is stored in the _piString
field as a string,
and the timePerDigit
field stores the time taken to compute one digit
of pi.
Source: https://www.i4cy.com/pi/
The class provides the following methods:
getNthDigit(int n)
: Retrieves the nth decimal digit of pi.containsPattern(String pattern)
: Checks if a given digit pattern exists in the decimal representation of pi.getDigits(int start, int end)
: Retrieves the digits of pi from the specified start to end indices.compute<T>(Decimal Function(Decimal) func)
: Applies a function that requires the value of pi to the computed value.countDigitFrequency()
: Counts the frequency of each digit in the decimal representation of pi.findPatternIndices(String pattern)
: Finds the indices of a given pattern in the string representation of pi.
Constructors
- PI.new({PiCalcAlgorithm algorithm = PiCalcAlgorithm.Chudnovsky, int? precision})
- Constructs a PI object with the specified precision.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- precision → int
-
The precision of the computed value of pi, in decimal places.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- timePerDigit ↔ double
-
The time taken per digit of the computed value of pi.
latefinal
- value → Decimal
-
The decimal value of π, with the specified precision.
no setter
Methods
-
binarySplit(
int a, int b) → (Decimal, Decimal, Decimal) -
Performs a binary split on the given range
a, b
to calculate the values of P, Q, and R for the Chudnovsky algorithm. -
compute<
T> (Decimal func(Decimal)) → Decimal - Computes a function that requires the value of π.
-
containsPattern(
String pattern) → bool - Checks if a given digit pattern exists in the decimal representation of π.
-
countDigitFrequency(
) → Map< String, int> - Counts the frequency of each digit in the provided string representation of pi.
-
findPatternIndices(
String pattern) → Map< String, dynamic> - Finds the indices of a given pattern in the string representation of pi, skipping the first two characters ("3.").
-
getDigits(
int start, int end) → String - Gets the digits of π from the specified start to end indices.
-
getNthDigit(
int n) → int - Gets the nth decimal digit of π.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited