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

# Python float

The `float` type in Python is a built-in numeric data type used to represent real numbers with a fractional component. In CPython, a `float` is implemented as a C `double`, meaning it strictly adheres to the IEEE 754 double-precision binary floating-point standard. It occupies 64 bits of memory: 1 bit for the sign, 11 bits for the exponent, and 52 bits for the significand (mantissa).

## Instantiation and Syntax

Floats can be instantiated using numeric literals containing a decimal point, scientific notation (E-notation), or the built-in `float()` constructor.

```python theme={"dark"}

# Decimal literals
val_standard = 3.14159
val_leading  = .5      # Evaluates to 0.5
val_trailing = 4.      # Evaluates to 4.0


# Scientific notation (E-notation)
val_large = 1.5e5      # Evaluates to 150000.0
val_small = 2.5e-3     # Evaluates to 0.0025


# Constructor casting
from_int = float(42)       # Evaluates to 42.0
from_str = float("-3.14")  # Evaluates to -3.14
```

## Special Values

The `float` type supports special IEEE 754 values representing infinity and undefined mathematical operations (Not a Number). These are typically instantiated via string casting.

```python theme={"dark"}
pos_inf = float('inf')   # Positive infinity
neg_inf = float('-inf')  # Negative infinity
nan_val = float('nan')   # Not a Number


# NaN identity quirk: NaN is never equal to itself
print(nan_val == nan_val)  # False
```

## Precision and Limits

Because Python floats are 64-bit double-precision values, they are subject to strict hardware limitations regarding maximum value and precision. These system-level constraints can be inspected using the `sys` module.

```python theme={"dark"}
import sys


# Maximum representable finite float
print(sys.float_info.max)      # ~1.7976931348623157e+308


# Minimum representable positive normalized float
print(sys.float_info.min)      # ~2.2250738585072014e-308


# Difference between 1.0 and the least value greater than 1.0
print(sys.float_info.epsilon)  # ~2.220446049250313e-16
```

## Representation Error

Because floats are stored as base-2 (binary) fractions, most base-10 (decimal) fractions cannot be represented exactly. This results in representation error, where the stored value is a highly precise approximation.

```python theme={"dark"}

# Binary approximation of 0.1 and 0.2 leads to a floating-point artifact
result = 0.1 + 0.2
print(result)          # 0.30000000000000004
print(result == 0.3)   # False


# Standard technical resolution for equality checks
import math
print(math.isclose(0.1 + 0.2, 0.3))  # True
```

## Type Methods

The `float` object includes several built-in methods for mathematical introspection and conversion.

```python theme={"dark"}
f = 3.125


# Returns a tuple of (numerator, denominator) in lowest terms
print(f.as_integer_ratio())  # (25, 8)


# Checks if the float has no fractional part
print(f.is_integer())        # False
print(3.0.is_integer())      # True


# Returns the exact hexadecimal string representation of the float
print(f.hex())               # '0x1.9000000000000p+1'
```

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