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

# Go float32

`float32` is a built-in primitive data type in Go that represents a 32-bit single-precision floating-point number, strictly conforming to the IEEE 754 standard. It occupies 4 bytes of memory and is composed of three parts: a 1-bit sign, an 8-bit exponent, and a 23-bit mantissa (fraction).

## Technical Specifications

* **Memory Footprint:** 32 bits (4 bytes)
* **Precision:** Approximately 7 decimal digits
* **Zero Value:** `0`
* **Maximum Value:** `math.MaxFloat32` ($\approx 3.4028235 \times 10^{38}$)
* **Smallest Non-Zero Value:** `math.SmallestNonzeroFloat32` ($\approx 1.401298 \times 10^{-45}$)

## Declaration and Type Inference

By default, Go's untyped floating-point constants and literals are inferred as `float64`. To instantiate a `float32`, explicit type declaration or type conversion is mandatory.

```go theme={"dark"}
package main

// Struct field definition
type Vector struct {
    X float32
    Y float32
}

func main() {
    // Explicit variable declaration
    var pi float32 = 3.141592

    // Short declaration using type conversion
    euler := float32(2.718281)
    
    _, _ = pi, euler
}
```

## Type Conversion

Go's strong typing system prohibits implicit type coercion. Operations involving `float32` and other numeric types (including `float64` and integers) require explicit type conversion.

```go theme={"dark"}
package main

func main() {
    var a float32 = 10.5
    var b float64 = 20.5

    // Invalid: c := a + b (mismatched types float32 and float64)

    // Valid: Convert float32 to float64
    c := float64(a) + b

    // Valid: Convert float32 to int (fractional part is truncated)
    d := int(a) // d equals 10
    
    _, _ = c, d
}
```

## Precision Limitations

Because `float32` is limited to 23 bits for the mantissa, it can only accurately represent about 7 decimal digits. Assigning a value that exceeds this precision results in rounding errors at the hardware level.

```go theme={"dark"}
package main

import "fmt"

func main() {
    // Exceeds 7 digits of precision
    var precise float32 = 12345678.9

    // The actual stored value will be 12345679.000000 due to precision loss
    fmt.Printf("%f\n", precise) 
}
```

## Special IEEE 754 Values

`float32` supports standard IEEE 754 non-numeric values, which can be generated using the `math` package. Because the `math` package functions return `float64`, they must be converted to `float32`.

```go theme={"dark"}
package main

import "math"

func main() {
    // Positive Infinity (+Inf)
    var posInf float32 = float32(math.Inf(1))

    // Negative Infinity (-Inf)
    var negInf float32 = float32(math.Inf(-1))

    // Not a Number (NaN)
    var nan float32 = float32(math.NaN())
    
    _, _, _ = posInf, negInf, 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 Go 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>
