> ## 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 num

The `num` type in Dart is an abstract class that serves as the root of the numeric type hierarchy. It provides a common interface for all numeric values and is the direct superclass for Dart's two concrete numeric types: `int` (integer values) and `double` (64-bit double-precision floating-point values). Because it is abstract, `num` cannot be directly instantiated; it acts as a polymorphic container for its subclasses.

## Type Resolution and Polymorphism

When a variable is declared as `num`, the Dart compiler permits it to hold either an `int` or a `double`. The exact type is resolved at runtime based on the assigned value.

```dart theme={"dark"}
num a = 10;      // Compile-time type: num. Runtime type: int.
num b = 10.5;    // Compile-time type: num. Runtime type: double.

a = 20.5;        // Valid: 'a' can be reassigned to a double because its static type is num.
```

## Platform-Specific Memory Representation

The underlying memory representation of `num` subclasses depends on the compilation target:

* **Native (Dart VM / AOT):** `int` is represented as a 64-bit two's complement integer. `double` is represented as an IEEE 754 64-bit double-precision floating-point number.
* **Web (JavaScript):** Because JavaScript lacks a distinct integer type, both `int` and `double` are mapped to JavaScript's `Number` type (IEEE 754 double-precision float). Consequently, on the web, `int` precision is restricted to $2^{53} - 1$ (the maximum safe integer in JavaScript).

## Core Properties

The `num` class defines several standard properties to evaluate the state of the numeric value:

```dart theme={"dark"}
num value = -42.5;

bool finite = value.isFinite;     // true (not NaN or infinity)
bool infinite = value.isInfinite; // false
bool nan = value.isNaN;           // false (Not-a-Number check)
bool negative = value.isNegative; // true
num sign = value.sign;            // -1.0 (Returns -1, 0, or 1 based on polarity)
```

## Core Methods

`num` provides a standard suite of mathematical and transformation methods inherited by both `int` and `double`:

**Type Conversion:**

```dart theme={"dark"}
num val = 42.9;
int asInt = val.toInt();       // 42 (truncates the fractional part)
double asDouble = val.toDouble(); // 42.9
```

**Rounding and Bounding:**

```dart theme={"dark"}
num val = 42.5;
num absolute = val.abs();             // 42.5
int ceiling = val.ceil();             // 43
int floor = val.floor();              // 42
int rounded = val.round();            // 43
int truncated = val.truncate();       // 42
num clamped = val.clamp(45.0, 50.0);  // 45.0 (bounds the value between lower and upper limits)
```

## Parsing

The `num` class provides static methods for parsing string literals into numeric types. The parser automatically infers whether to return an `int` or a `double` based on the presence of a decimal point or exponent.

```dart theme={"dark"}
num parsed1 = num.parse('42');      // Returns int: 42
num parsed2 = num.parse('42.5');    // Returns double: 42.5

// tryParse returns null instead of throwing a FormatException on failure
num? safeParse = num.tryParse('invalid_number'); // Returns null
```

## Operator Restrictions

While `num` supports standard arithmetic operators (`+`, `-`, `*`, `/`, `%`, `~/`), it **does not** support bitwise operators (`&`, `|`, `^`, `~`, `<<`, `>>`, `>>>`). Bitwise operations are strictly defined on the `int` class. To perform bitwise operations on a `num` variable, it must first be explicitly cast or converted to an `int`.

```dart theme={"dark"}
num x = 5;
num y = 3;

// num result = x & y; // COMPILATION ERROR: The operator '&' isn't defined for the class 'num'.
int result = x.toInt() & y.toInt(); // Valid
```

<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>
