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

# Rust f64

The `f64` type in Rust is a primitive data type representing a 64-bit, double-precision floating-point number as defined by the IEEE 754-2008 standard. It serves as Rust's default floating-point type during type inference.

## Memory Layout

An `f64` occupies exactly 8 bytes (64 bits) of memory. Its internal bitwise architecture is divided into three fields:

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

## Syntax and Initialization

Rust provides multiple ways to declare an `f64` literal. If a floating-point literal lacks a type suffix and the type is not explicitly annotated, the compiler infers `f64`.

```rust theme={"dark"}
let implicit = 3.14;               // Inferred as f64
let explicit: f64 = 3.1415926535;  // Explicit type annotation
let suffixed = 2.718_f64;          // Type suffix
let scientific = 6.022e23;         // Scientific notation (inferred f64)
```

## Precision and Limits

Because of the 52-bit mantissa, an `f64` guarantees a precision of **15 to 17 significant decimal digits**.

The `std::f64` module defines its mathematical boundaries:

* `f64::MAX`: \~1.7976931348623157 × 10³⁰⁸
* `f64::MIN`: \~-1.7976931348623157 × 10³⁰⁸
* `f64::MIN_POSITIVE`: \~2.2250738585072014 × 10⁻³⁰⁸ (smallest positive normal value)
* `f64::EPSILON`: \~2.2204460492503131 × 10⁻¹⁶ (difference between 1.0 and the next representable value)

## Special IEEE 754 Values

`f64` supports special states representing undefined or unrepresentable mathematical operations:

```rust theme={"dark"}
let not_a_number = f64::NAN;          // Result of 0.0 / 0.0
let infinity = f64::INFINITY;         // Result of 1.0 / 0.0
let neg_infinity = f64::NEG_INFINITY; // Result of -1.0 / 0.0
```

## Trait Implementations and Equivalence

A critical technical distinction in Rust is that `f64` **does not implement the `Eq` or `Ord` traits**. It only implements `PartialEq` and `PartialOrd`.

This is a direct consequence of IEEE 754 rules regarding `NaN` (Not-a-Number). `NaN` is never equal to anything, including itself.

```rust theme={"dark"}
let x = f64::NAN;
assert!(x != x); // Evaluates to true
```

Because `f64` lacks total equality (`Eq`) and total ordering (`Ord`), it cannot be directly used as a key in a `HashMap` or `BTreeMap`, nor can a slice of `f64` be sorted using the standard `.sort()` method.

## Total Ordering (`total_cmp`)

To establish a strict weak ordering for floating-point numbers, Rust provides the `f64::total_cmp` method. This method implements the IEEE 754 `totalOrder` predicate, allowing `f64` values (including `NaN`) to be safely sorted or used in ordered collections.

```rust theme={"dark"}
let mut floats = [3.1, 1.2, f64::NAN, 4.5];
// floats.sort(); // COMPILER ERROR: f64 does not implement Ord

// Idiomatic, safe approach for sorting f64:
floats.sort_unstable_by(|a, b| a.total_cmp(b));
```

## Standard Library Methods

The `f64` primitive has built-in mathematical methods provided by the standard library. Note that in `no_std` environments (using only the `core` library), complex mathematical functions (like trigonometry or logarithms) are unavailable by default because they rely on the system's C math library (`libm`).

```rust theme={"dark"}
let val = -4.0_f64;
let abs_val = val.abs();           // 4.0
let square_root = abs_val.sqrt();  // 2.0
let power = square_root.powf(3.0); // 8.0
let rounded = 3.7_f64.floor();     // 3.0
```

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