> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dart BigInt

`BigInt` is a built-in Dart class representing an arbitrarily large integer. Unlike the standard `int` type, which is constrained to a 64-bit two's complement representation (ranging from -2^63 to 2^63 - 1), `BigInt` can store integer values of any size, limited only by the available system memory.

## Instantiation

Because Dart's numeric literals are parsed as 64-bit integers by the compiler, instantiating a `BigInt` that exceeds the 64-bit limit requires parsing from a `String`. Using `BigInt.from()` with a numeric literal that exceeds the 64-bit limit results in a compile-time error.

```dart theme={"dark"}
// Recommended: Parsing from a string prevents 64-bit overflow errors
BigInt largeBase10 = BigInt.parse('922337203685477580899999');

// Automatically detects and parses hexadecimal if prefixed with '0x'
BigInt largeHex = BigInt.parse('0x1fffffffffffff123456789');

// Parsing without a prefix requires explicitly specifying the radix
BigInt explicitHex = BigInt.parse('1fffffffffffff123456789', radix: 16);
BigInt binaryValue = BigInt.parse('101010', radix: 2);

// Converting from an existing 64-bit int or double
BigInt fromNativeInt = BigInt.from(42);

// Pre-defined constants
BigInt zero = BigInt.zero;
BigInt one = BigInt.one;
BigInt two = BigInt.two;
```

## Operators

`BigInt` overloads standard arithmetic, relational, and bitwise operators. This allows instances to be manipulated using the same syntax as native `int` types.

```dart theme={"dark"}
BigInt a = BigInt.parse('100000000000000000000');
BigInt b = BigInt.from(5);

// Arithmetic
BigInt sum = a + b;
BigInt difference = a - b;
BigInt product = a * b;
BigInt quotient = a ~/ b;     // Truncating integer division, returns BigInt
double floatQuotient = a / b; // Standard division, returns double
BigInt modulo = a % b;

// Bitwise
BigInt shifted = a << 2;
BigInt bitwiseAnd = a & b;

// Relational
bool isGreater = a > b;
```

*Note: The standard division operator (`/`) is fully supported between `BigInt` instances, but it evaluates to a `double`. To maintain arbitrary precision and return a `BigInt`, use the truncating division operator (`~/`).*

## Key Properties and Methods

`BigInt` provides several properties and methods for mathematical operations and state inspection.

```dart theme={"dark"}
BigInt val = BigInt.parse('256');

// Inspection
bool isEven = val.isEven;
bool isNegative = val.isNegative;
int sign = val.sign;      // Returns -1, 0, or 1
int bits = val.bitLength; // Minimum number of bits required to store the value

// Mathematical operations
BigInt power = val.pow(3);
BigInt greatestCommonDivisor = val.gcd(BigInt.from(128));

// Downcasting
int nativeInt = val.toInt();          // Truncates if value exceeds 64 bits
double nativeDouble = val.toDouble(); // Loses precision if value exceeds 53 bits
```

## Technical Characteristics

* **Immutability:** Instances of `BigInt` are strictly immutable. All arithmetic and bitwise operations allocate and return a new `BigInt` instance in memory.
* **Performance Overhead:** Because `BigInt` utilizes software-based arbitrary-precision arithmetic rather than hardware-level CPU instructions, operations are significantly slower and consume more memory than native `int` operations.
* **Web Compilation:** When compiled to the web via `dart2js` or `dartdevc` (DDC), Dart's `BigInt` uses a custom Dart implementation (a class backed by arrays of smaller integers) to guarantee consistent semantics with the Dart VM. It does not map to the native JavaScript `BigInt` type. Native JS BigInts are instead accessed via JS interop (e.g., `JSBigInt`).

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Dart Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
