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

The `%` operator in Dart is the arithmetic modulo operator, which calculates the Euclidean remainder of a division operation between two numbers. Unlike the modulo operator in many C-style languages (which perform a truncating remainder), Dart's `%` operator strictly enforces Euclidean division, guaranteeing that the returned remainder is always non-negative regardless of the operands' signs.

```dart theme={"dark"}
num result = dividend % divisor;
```

## Type Evaluation

The static and runtime return type of the `%` operation is determined by the types of its operands:

* If both operands are of type `int`, the operation yields an `int`.
* If at least one operand is of type `double`, the operation yields a `double`.

```dart theme={"dark"}
int intResult = 10 % 3;         // Evaluates to 1
double doubleResult = 10.5 % 3; // Evaluates to 1.5
```

## Euclidean Modulo Behavior

Dart calculates the modulo such that the result `r` always satisfies the mathematical condition `0 <= r < |divisor|`. Because it is a Euclidean modulo, negative operands will not produce a negative remainder.

```dart theme={"dark"}
// Standard positive operands
print(5 % 3);   // Evaluates to 2

// Negative dividend
print(-5 % 3);  // Evaluates to 1 (Contrast with C++/Java which yield -2)

// Negative divisor
print(5 % -3);  // Evaluates to 2

// Negative dividend and divisor
print(-5 % -3); // Evaluates to 1
```

*Note: If you require a truncating remainder operation where the result retains the sign of the dividend, Dart provides the `num.remainder()` method as the strict alternative to the `%` operator.*

## Exceptional Cases

The behavior of the `%` operator when the divisor is zero diverges based on the operand types:

* **Integer Division by Zero:** Evaluating `int % 0` throws an `UnsupportedError` (Integer division by zero).
* **Floating-Point Division by Zero:** Evaluating `double % 0` or `num % 0.0` does not throw. Instead, it evaluates to `NaN` (Not a Number) in compliance with IEEE 754 floating-point standards.

```dart theme={"dark"}
int a = 5 % 0;       // Throws UnsupportedError
double b = 5.0 % 0;  // Evaluates to NaN
double c = 5 % 0.0;  // Evaluates to NaN
```

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