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

# C# double

The `double` keyword in C# is a built-in value type that represents a double-precision, 64-bit floating-point number. It serves as a language alias for the .NET `System.Double` struct and strictly adheres to the IEEE 754 standard for binary floating-point arithmetic.

## Technical Specifications

* **Memory Size:** 64 bits (8 bytes)
* **Precision:** 15 to 17 decimal digits
* **Minimum Value:** `-1.7976931348623157E+308` (`double.MinValue`)
* **Maximum Value:** `1.7976931348623157E+308` (`double.MaxValue`)
* **Smallest Non-Zero Value:** `4.9406564584124654E-324` (`double.Epsilon`)

## Memory Layout (IEEE 754)

The 64 bits of a `double` are partitioned into three distinct components:

1. **Sign bit:** 1 bit (determines positive or negative)
2. **Exponent:** 11 bits (determines the magnitude)
3. **Mantissa (Significand):** 52 bits (determines the precision)

## Syntax and Literals

By default, any real numeric literal on the right side of an assignment containing a decimal point is treated as a `double` by the C# compiler. You can also explicitly denote a `double` literal using the `d` or `D` suffix, or utilize scientific (exponential) notation using `e` or `E`.

```csharp theme={"dark"}
// Implicit literal inference
double defaultLiteral = 3.14159;

// Explicit suffix
double explicitLiteral = 3.14159d;
double explicitLiteralUpper = 3.14159D;

// Scientific notation
double scientificNotation = 1.5e-4; // Evaluates to 0.00015
double scientificNotationUpper = 2.5E3; // Evaluates to 2500.0
```

## Special Constants

The `System.Double` struct exposes several constant fields to handle edge cases in floating-point arithmetic, such as division by zero or undefined operations.

```csharp theme={"dark"}
// Represents a value that is not a number (e.g., result of 0.0 / 0.0)
double nanValue = double.NaN;

// Represents positive infinity (e.g., result of 1.0 / 0.0)
double posInfinity = double.PositiveInfinity;

// Represents negative infinity (e.g., result of -1.0 / 0.0)
double negInfinity = double.NegativeInfinity;
```

## Type Conversions

**Implicit Conversions:**
C# allows implicit conversions to `double` from any integral type (`sbyte`, `byte`, `short`, `ushort`, `int`, `uint`, `long`, `ulong`), as well as from `float` and `char`.

```csharp theme={"dark"}
int integerVal = 42;
double implicitFromInt = integerVal; 

float floatVal = 3.14f;
double implicitFromFloat = floatVal;
```

**Explicit Conversions:**
Converting from `double` to integral types or the `decimal` type requires an explicit cast. Casting to an integral type truncates the value towards zero. Casting to `decimal` requires an explicit cast because `double` is a base-2 floating-point type with a massive range, whereas `decimal` is a base-10 floating-point type with a significantly smaller range. This conversion can result in precision loss or an `OverflowException`.

```csharp theme={"dark"}
double originalValue = 9.99;

// Requires explicit cast; fractional part is truncated
int truncatedInt = (int)originalValue; // Evaluates to 9

// Requires explicit cast due to base-2 to base-10 conversion and range differences
decimal decimalValue = (decimal)originalValue; 
```

## Precision and Comparison Pitfalls

Because `double` utilizes base-2 binary fractions, it cannot accurately represent certain base-10 fractional values (such as `0.1`). This inherent limitation of binary floating-point arithmetic means that `double` should **never** be used for financial or monetary calculations; the `decimal` type must be used instead.

Furthermore, due to these floating-point arithmetic inaccuracies, developers should avoid using the equality operator (`==`) to compare two `double` values. Instead, comparisons should check if the absolute difference between the two values is within a small, acceptable margin of error (tolerance).

```csharp theme={"dark"}
double a = 0.1 * 3.0;
double b = 0.3;

// Incorrect: Evaluates to false due to floating-point imprecision (0.30000000000000004 != 0.3)
bool isEq = (a == b); 

// Correct: Compares the absolute difference against a small tolerance
double tolerance = 1e-10;
bool isEffectivelyEq = Math.Abs(a - b) < tolerance; // Evaluates to true
```

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